Conditionally Returning Data

Conditionally returning values for rows

Here is a query that returns the movies that Charlie Chaplin has acted in and the runtime for the movie.

cypher
MATCH (m:Movie)<-[:ACTED_IN]-(p:Person)
WHERE p.name = 'Charlie Chaplin'
RETURN m.title AS movie,
// Add CASE clause code here
m.runtime AS runTime

Modify this query to return "Short" for runTime if the movie’s runtime is < 120 (minutes) and "Long" for runTime if the movie’s runtime is >= 120.

Then answer this question:

How many short movies?

How many rows returned a value of Short for Runtime?

  • ✓ 6

Hint

Modify the query so that "Short" or "Long" is returned where you use a CASE clause to conditionally return the value.

How many Short movies are 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 (m:Movie)<-[:ACTED_IN]-(p:Person)
WHERE p.name = 'Charlie Chaplin'
RETURN m.title AS Movie,
CASE
WHEN m.runtime < 120 THEN "Short"
WHEN m.runtime >= 120 THEN "Long"
ELSE "Unknown"
END AS Runtime

How many Short does it return?

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

Summary

In this challenge, you modified a query to return conditional results.

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