I have a question about exercise 5.11: ‘Retrieve the actors who have acted in exactly five movies, returning the name of the actor, and the list of movies for that actor.’ The solution in the course is as follows:
MATCH (a:Person)-[:ACTED_IN]->(m:Movie)
WITH a, count(a) AS numMovies, collect(m.title) AS movies
WHERE numMovies = 5
RETURN a.name, movies
Why is the count on a:Person? It seems this query counts the number of Persons who have one or more :ACTED_IN relation with a Movie.
My solution is as follows:
MATCH (p:Person)-[acted:ACTED_IN]->(m:Movie)
WITH p, count(acted) AS numMovies, collect(m.title) AS movies
WHERE numMovies = 5 RETURN p.name, movies
I count on the relation :ACTED_IN. This seems more logical to me: for any given Person, I want to know how many times the relation :ACTED_IN occurs. Then I select the Persons who have exactly five of those relations.
Can anyone explain why the solution in the course has a count on a:Person?