Movies with 1 or 2 Actors
Write and execute a query to return the movies that have one or two actors. You will return the movie title, the year the movie was released and the actors for the movie.
Once you executed, enter the number of movies returned below and click Check Answer.
-
✓ 139
Hint
Your query should:
-
Find all movies with actors. (single path using the
:ACTED_IN
relationship) -
Collect the actor names nodes as a list. (Use `WITH)
-
Test the size of the Actors list to be less than or equal to 2.(Use
WHERE
) -
Return the movie title, movie year and Actors.
How many movies does it return?
Once you have entered the answer, click the Try Again button below to continue.
Solution
You can run the following query to find the answer:
MATCH (m)<-[:ACTED_IN]-(a:Person)
WITH m, collect(a.name) AS Actors
WHERE size(Actors) <= 2
RETURN m.title AS Movie, m.year as Year, Actors ORDER BY m.year
How many movies does it return?
Once you have entered the answer, click the Try Again button below to continue.
Summary
In this challenge, you wrote and executed a query to answer a question about the graph where you aggregated data.
In the next lesson, you will learn about aggregation with count()
.