Using WITH to scope variables
Update the WITH
clause in this query to scope the required variables.
cypher
WITH 'Tom Hanks' AS theActor
MATCH (p:Person)-[:ACTED_IN]->(m:Movie)
WHERE p.name = theActor
AND m.revenue IS NOT NULL
WITH ??????, ?????? ORDER BY m.revenue DESC LIMIT 1
RETURN theActor, m.title AS title, m.revenue AS revenue
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
You will need to use WITH
to pass the theActor
and m
variables.
Solution
The answer is Toy Story 3
.
Run the following query to see the result:
cypher
WITH 'Tom Hanks' AS theActor
MATCH (p:Person)-[:ACTED_IN]->(m:Movie)
WHERE p.name = theActor
AND m.revenue IS NOT NULL
WITH theActor, m ORDER BY m.revenue DESC LIMIT 1
RETURN theActor, m.title AS title, m.revenue AS revenue
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.