Ages of Actors
Write a query to return a list containing the ages of the actors for the Movie Toy Story. The age you return is the age of the actor when the movie was released.
What is the age at the time the movie was released of the oldest actor who acted in this movie?
Once you execute the query, enter the age of the oldest actor below and click Check Answer.
-
✓ 69
Hint
Start with this MATCH
clause to retrieve the movie Toy Story.
Collect the actors for this movie.
Return the ages of the actors as a list.
Use date(m.released).year - x.born.year
to calculate the age of each actor.
What is the age at the time the movie was released of the oldest actor who acted in this movie?
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)--(m:Movie)
WHERE m.title = 'Toy Story'
WITH m, collect (a) AS Actors
RETURN [x IN Actors | date(m.released).year - x.born.year] AS Ages
What is the age at the time the movie was released of the oldest actor who acted in this movie?
Once you have entered the answer, click the Try Again button below to continue.
Summary
In this challenge, you wrote a query that uses list comprehension to return the ages of the actors for a movie. In the next module, you will learn about the aggregating functions available in Cypher.