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.
To work through this recipe, you will need to create the nodes and relationships for which data has been provided with the code files.
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 Neo4j console depicting nodes and
count
of relationships they share with the other nodes in the graph:Count the number of entities: Let's
count
the total number of flights originating from any airport:START n = node(*)MATCH (n)-[r:`ORIGIN`]->(o...