Cypher Aggregations
Master Cypher aggregation in Neo4j: count, collect, sum, avg, min, max, and percentile functions, plus lists and pattern comprehension, hands-on.
In this 1-hour course, you will learn
This course teaches you how Full definition for aggregation (opens in a new tab)Grouping rows and computing a value over each group. In Cypher the grouping keys are whatever expressions in the same clause are not aggregated. works in Full definition for Cypher (opens in a new tab)Neo4j's implementation of GQL, the ISO standard query language for graph databases. It is declarative: you describe the pattern to find, and the database decides how to find it., Neo4j's query language, and how to use aggregating and list functions to summarise graph data. In around 60 minutes you will move from collecting values into lists to calculating sums, averages, and percentiles, working hands-on against a recommendations dataset of movies, people, users, genres, and ratings.
Aggregation is how you turn thousands of individual Full definition for node (opens in a new tab)A vertex in a graph. In a property graph it can carry labels and properties. and Full definition for relationship (opens in a new tab)A named, directed connection between two nodes. Every relationship has a type, a start node and an end node. into answers: how many movies did an actor appear in, what is the average rating for a film, which reviews are the most recent. Cypher handles grouping differently from SQL, and understanding that difference is the key to writing aggregations that are both correct and fast.
Profile and Explain How Aggregation Works at Runtime
Use PROFILE and EXPLAIN to inspect query execution plans and understand how Cypher processes aggregation steps, partition boundaries, and operator costs at runtime.
Work with Lists
Build, filter, and transform lists using list comprehension and pattern comprehension to collect, reshape, and traverse graph data in a single expression.
Use Aggregating Functions
Apply count, collect, sum, avg, min, max, and percentile functions to summarise graph data across nodes and relationships and return meaningful rolled-up results.
3 modules, 1 hour.
- Scalar List Functions5 min
- Finding the Oldest Actor5 min
- Calculating Total Votes5 min
- Functions that Return Lists5 min
- Finding Latest Review5 min
- Finding Common Reviewers5 min
- Functions to Transform Element Types5 min
- Transforming Movie Reviews5 min
- Testing Lists with Predicate Functions5 min
- Filtering Tom Hanks Movies5 min
- Using List Comprehension to Aggregate5 min
- Calculating Actor Ages5 min
Who this course is for
This course is for developers, data engineers, and analysts who can already read and write basic Full definition for Cypher (opens in a new tab)Neo4j's implementation of GQL, the ISO standard query language for graph databases. It is declarative: you describe the pattern to find, and the database decides how to find it. and want to summarise data rather than just retrieve it. If you find yourself exporting query results to another tool just to count, average, or rank them, this course shows you how to do that work directly in the database, in a single query. It is also useful preparation for anyone building reports, dashboards, or recommendation features on top of Neo4j. You should be comfortable with
MATCH,WHERE, andRETURNfrom Cypher Fundamentals before you start, because every lesson builds Full definition for aggregation (opens in a new tab)Grouping rows and computing a value over each group. In Cypher the grouping keys are whatever expressions in the same clause are not aggregated. on top of those clauses.What you'll do
This is a hands-on course. You work in an embedded sandbox connected to a live Neo4j database loaded with the recommendations dataset: movies, the people who acted in and directed them, the users who rated them, and the genres that classify them. It is a realistic graph with enough data that Full definition for aggregation (opens in a new tab)Grouping rows and computing a value over each group. In Cypher the grouping keys are whatever expressions in the same clause are not aggregated. results are meaningful, not toy numbers.
Every concept is paired with a query you run yourself, and each lesson is followed by a challenge that checks your answer against the graph. You collect values into lists with
collect()and Full definition for pattern (opens in a new tab)A graph structure written in Cypher, such as a node joined to another node by a relationship. comprehension, count Full definition for node (opens in a new tab)A vertex in a graph. In a property graph it can carry labels and properties. and Full definition for relationship (opens in a new tab)A named, directed connection between two nodes. Every relationship has a type, a start node and an end node., reshape and filter lists with functions such assize(),head(), and list comprehension, and calculate totals, averages, and percentiles of real ratings withsum(),avg(),min(),max(), andpercentileCont(). You cannot pass a challenge by reading alone, so by the end you have proven you can write working aggregations, not just recognise them.Where to go next
Working with Dates and Durations is the natural next step. Many of the values you aggregate in real projects are temporal — review dates, release years, career spans — and that course teaches you to convert, compare, and calculate with Neo4j's temporal types. The Neo4j Certified Professional exam tests Full definition for aggregation (opens in a new tab)Grouping rows and computing a value over each group. In Cypher the grouping keys are whatever expressions in the same clause are not aggregated. alongside the rest of Full definition for Cypher (opens in a new tab)Neo4j's implementation of GQL, the ISO standard query language for graph databases. It is declarative: you describe the pattern to find, and the database decides how to find it., so the functions you practise here count directly toward a recognised, industry-standard credential.
Posts from the GraphAcademy blog.
My five favorite cards in Aura Dashboards
When Dashboards first became available in Aura, I started to move my reporting away from custom tools. Here are the five cards I use the most, and a Cypher statement behind them.
SQL to Cypher - 10 Queries You Already Know
You already know how to write these queries. This article shows you what they look like when the joins go away.
Writing Cypher Queries That Don't Lose Your Data
The query trap that hides your newest data, and the query shape that brings it back.