O'Reilly logo

Neo4j Cookbook by Ankur Goel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required