Data aggregation summarizes rows returned by a Cypher query. It starts with counts of nodes, relationships, values, and graph patterns, then uses those summaries to describe a graph dataset or answer an analysis question. section 4.2 section 4.4
Use aggregation to:
- Distinguish count(*)—all produced rows—from count(expression), which ignores null values. Comparing them exposes missing property values. section 4.2
- Group counts by node labels or relationship types to summarize graph structure. section 4.2
- Calculate ratios carefully: cast an integer to float before division when a fractional percentage is needed. section 4.2
- Control intermediate cardinality between MATCH clauses. Aggregate with WITH before another match to avoid multiplying rows and producing incorrect counts. section 4.5
- Count a node's matching pattern with count {} when multiple aggregations would otherwise increase the main query's cardinality. section 4.4
Checking registration-date completeness
Match User nodes, count all rows, and count u.registeredAt. The difference identifies users without a registration date; casting the non-null count to float before division yields the percentage present. section 4.2
Counting users and tweets safely
Two independent MATCH clauses can form a 3,594-by-12,060 row product. Count users in a WITH clause first, reducing the intermediate result to one row before matching tweets. section 4.5
Listing 4.4 Calculating the ratio of non-null values of registeredAt node property
MATCH (u:User) #1
WITH count(*) AS numberOfRows,
count(u.registeredAt) AS usersWithRegisteredAtDate #2
RETURN toFloat(usersWithRegisteredAtDate) / numberOfRows * 100 AS result #3
This query shows the complete pattern for counting non-null values and converting one count to float before calculating a percentage. section 4.2


















