Aggregation with Cypher

The Cypher query offers aggregation similar to GROUP BY offered by SQL. The aggregate function can take multiple values and can calculate the aggregated values for them. In this recipe, we will learn the common aggregation techniques, with the help of examples.

Getting ready

To work through this recipe, you will need to create the nodes and relationships for which data has been provided with the code files.

How to do it...

We have divided this recipe into the following problem sets:

  • Nodes and relationships: Let's get all the nodes and then count the number of relationships they have with the other nodes:
    START n = node(*) 
    MATCH n-[r]-() RETURN n, count(r) as rel_count ORDER BY rel_count desc

    The following screenshot shows the ...

Get Neo4j Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.