Counting results
Most active director?
Find the highest number of movies directed by a single director.
Update this query to count the number of movies for each director.
cypher
MATCH (d:Director)-[:DIRECTED]-(m)
RETURN
d.name AS director,
?????? AS numMovies
ORDER BY numMovies DESC LIMIT 5
Enter the name of director who has directed the most movies (case-sensitive)?
-
✓ Woody Allen
Hint
You will need to use the count()
aggregation function.
You can pass *
to count
to count all the returned elements.
Solution
The answer is Woody Allen
.
Run the following query to see the result:
cypher
MATCH (d:Director)-[:DIRECTED]-(m)
RETURN
d.name AS director,
count(*) AS numMovies
ORDER BY numMovies DESC LIMIT 5
Summary
In this challenge, you wrote a query to aggregate results so you could answer a question about the data.
In the next challenge, you will write a query to create lists.