Using Subqueries

Add a subquery

Top Genres

Complete this query to find the number of movies in each genre that have a imdbRating greater than 9.

cypher
MATCH (g:Genre)
?????? { 
    WITH ??????
    MATCH (g)<-[:IN_GENRE]-(m) WHERE m.imdbRating > 9
    RETURN count(m) AS numMovies
}
RETURN g.name AS Genre, numMovies 
ORDER BY numMovies DESC

You will need to call the subquery and pass the Genre variable.

What is the top Genre with the most movies that have an imdbRating greater than 9? (case-sensitive)

  • ✓ Drama

Hint

You use CALL to call the subquery.

The variable g is required by the subquery to find the Genre.

Solution

The answer is Drama.

Run the following query to see the result:

cypher
MATCH (g:Genre)
CALL { 
    WITH g
    MATCH (g)<-[:IN_GENRE]-(m) WHERE m.imdbRating > 9
    RETURN count(m) AS numMovies
}
RETURN g.name AS Genre, numMovies ORDER BY numMovies DESC

Summary

In this challenge, you answered a question by writing a Cypher subquery.

In the next challenge you will write a query to combine results.