Total imdbVotes for Tom Hanks
Using reduce()
write a query that returns the total of all imdbVotes for movies that Tom Hanks acted in.
What is the total of imdbVotes for the movies that Tom Hanks acted in? (Enter the number without commas)
Once you executed, enter the total below and click Check Answer.
-
✓ 7836629
Hint
Use MATCH
to retrieve all Movie nodes that Tom Hanks acted in.
Add a WITH
clause to collect the movie imdbVotes property values.
Add a WITH
clause to process each value in the list created to total the imdbVotes using the reduce()
function.
RETURN
the total calculate by the reduce()
function.
What is the total of imdbVotes for the movies that Tom Hanks acted in? (Enter the number without commas)
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 (a:Actor)-[:ACTED_IN]->(m:Movie)
WHERE a.name = 'Tom Hanks'
WITH collect(m.imdbVotes) AS Votes
WITH reduce(Init = 0, x IN Votes | Init + x) AS TotalVotes
RETURN TotalVotes
What is the total of imdbVotes for the movies that Tom Hanks acted in? (Enter the number without commas)
Once you have entered the answer, click the Try Again button below to continue.
Summary
In this challenge, you wrote a query that uses reduce()
to return the total of imdbVotes for movies that Tom Hanks acted in.
In the next lesson, you will learn about Cypher functions that return lists.