Graph databases: Practical Exercises

We assume you have already completed the tutorial on a separate page.

Please use the Cypher query language to solve each of the following exercises.

In Moodle, please submit three files: exercise2a.cypher, exercise2b.cypher, and exercise2c.cypher. If you haven't completed all parts, you can submit blank files. However, we recommend developing and debugging on your own machine before going to Moodle.

Exercise 2.a

Recall our solution to Exercise 1a from the SQL tutorial:

SELECT name, count(*) AS total
FROM people
JOIN credits  ON credits.person_id = people.id AND type = 'writer'
JOIN genres ON genres.movie_id = credits.movie_id AND genre = 'Drama'
GROUP BY name
ORDER BY total desc, name
LIMIT 10;

This query returns the name of a person and the total number of movies having genre Drama for which that person is a writer.

Complete the following Cypher query so that you produce the same output as the SQL query. This should help you better appreciate the pattern matching features of the Cypher language!

   YOUR-CODE-GOES-HERE
   return p.name as name, count(*) as total
   order by total desc, name
   limit 10;

Exercise 2.b

Write a Cypher query that returns pairs name and title where title is the title of a movie and name is the name of a person that acts in, directs, produces, and edits that movie.

   YOUR-CODE-GOES-HERE
   order by name, title;

Exercise 2.c

Write a Cypher query that returns pairs name and title where title is the title of a movie and name is the name of a person that acts in and directs that movie and where that movie has both Action and Adventure as genres. Try to write you query using one match expression (containing no commas).

   YOUR-CODE-GOES-HERE
   order by name, title;