Highest Revenue Movies

Using WITH to scope variables

Add a WITH clause to this query so that the movie with the highest revenue is returned:

cypher
WITH  'Tom Hanks' AS theActor
MATCH (p:Person)-[:ACTED_IN]->(m:Movie)
WHERE p.name = theActor
AND m.revenue IS NOT NULL
// Use WITH here to limit the movie node to 1 and order it by revenue
RETURN m.revenue AS revenue, m.title AS title

Answer this question:

What is the highest revenue movie for Tom Hanks?

What movie had the highest revenue? (Note, the answer is case-sensitive)?

  • ✓ Toy Story 3

Hint

Make sure you pass on m in the WITH clause. Specify ORDER BY before LIMIT

What is the name of the movie? (case-sensitive)

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
WITH  'Tom Hanks' AS theActor
MATCH (p:Person)-[:ACTED_IN]->(m:Movie)
WHERE p.name = theActor
AND m.revenue IS NOT NULL
WITH m ORDER BY m.revenue DESC LIMIT 1
RETURN m.revenue AS revenue, m.title AS title

What is the name of the movie? (case-sensitive)

Once you have entered the answer, click the Try Again button below to continue.

Summary

In this challenge, you modified a query to use a WITH clause to limit and order nodes.

In the next challenge, you will answer another question about this query.