cancel
Showing results for 
Search instead for 
Did you mean: 

Weekly Challenge #3 Lots of directors...

TrevorS
Community Team
Community Team

Create a recommendations sandbox at sandbox.neo4j.com.

For this dataset, write a query that returns one row for every movie in the graph that has at least 10 directors. 

It will also return the list of reviewers for each movie. 

 

Each row will contain: 

  • Movie (title of the movie) 
  • DIrectors (list of the names of the directors for that movie) 
  • Reviewers (list of the names of the reviewers of that movie) 
TrevorS
Community Specialist
2 ACCEPTED SOLUTIONS

Cobra
Ninja
Ninja

Hello @TrevorS 😊

Here is the query:

MATCH (m:Movie) 
WHERE size((m)<-[:DIRECTED]-()) >= 10 
RETURN m.title AS title, [(m)<-[:DIRECTED]-(d) | d.name] AS directors, [(m)<-[:RATED]-(u) | u.name] AS reviewers;

Here is the screenshot:

Weekly Challenge #3.png

Regards,
Cobra

View solution in original post

loois
Node

Hello @TrevorS,

MATCH (n:Movie)
WHERE size((n)<-[:DIRECTED]-()) >= 10
WITH n { .title,
directors: [ (n)<-[:DIRECTED]-(p) | p.name],
reviewers: [ (n)<-[:RATED]-(g) | g.name]
}
RETURN n.title AS title, n.directors AS directors, n.reviewers AS reviewers

I've just started learning Neo4j and I'm currently completing the Intermediate Cypher Queries course when I saw the challenge and decided to share this. 

loois_0-1660749661176.png

Regards,

L

View solution in original post

5 REPLIES 5

Cobra
Ninja
Ninja

Hello @TrevorS 😊

Here is the query:

MATCH (m:Movie) 
WHERE size((m)<-[:DIRECTED]-()) >= 10 
RETURN m.title AS title, [(m)<-[:DIRECTED]-(d) | d.name] AS directors, [(m)<-[:RATED]-(u) | u.name] AS reviewers;

Here is the screenshot:

Weekly Challenge #3.png

Regards,
Cobra

Great job @Cobra 

loois
Node

Hello @TrevorS,

MATCH (n:Movie)
WHERE size((n)<-[:DIRECTED]-()) >= 10
WITH n { .title,
directors: [ (n)<-[:DIRECTED]-(p) | p.name],
reviewers: [ (n)<-[:RATED]-(g) | g.name]
}
RETURN n.title AS title, n.directors AS directors, n.reviewers AS reviewers

I've just started learning Neo4j and I'm currently completing the Intermediate Cypher Queries course when I saw the challenge and decided to share this. 

loois_0-1660749661176.png

Regards,

L

Hello @loois ,

Your query performs just as well as the query from @Cobra . Both are great solutions.

Good luck on your Cypher learning journey @loois 

glilienfield
Ninja
Ninja

These all are the same idea.  

match (m:Movie)<-[:DIRECTED]-(p)
with m, count(p) as count
where count > 9
match (m)<-[:DIRECTED]-(p)
with m, collect(p.name) as directors
match (m)<-[:RATED]-(u)
return m.title as title, directors, collect(u.name) as reviewers

Screen Shot 2022-08-17 at 4.58.52 PM.png

 Is it any better?

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.