Counting Nodes

Actors in Comedy Movies

Write and execute a query return the number of actors who acted in a Comedy movie.

What is the number returned?

Once you executed, enter the number of movies returned below and click Check Answer.

  • ✓ 6666

Hint

Your query should:

Find all movies with actors who acted in a Comedy movie:

MATCH (p:Person)-[:ACTED_IN]→(m:Movie)-[:IN_GENRE]→(g:Genre) WHERE g.name = 'Comedy'

Then return the number of unique Person names.

What is the number returned?

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:

cypher
MATCH (p:Person)-[:ACTED_IN]->(m:Movie)-[:IN_GENRE]->(g:Genre)
WHERE g.name = 'Comedy'
RETURN count (DISTINCT p.name)

What is the number returned?

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 counted nodes.

In the next lesson, you will learn about aggregation using pattern comprehension.