Use `count()` to turn matched graph patterns into totals. `count(*)` returns the number of rows produced by a query, while `count(variableOrExpression)` returns only non-null values. This makes the function useful for counting nodes, relationships, matches, and populated properties. section 4.2
Check property completeness
To compare User records with available registration dates, count all matched rows and then count the `registeredAt` values. A difference between the totals reveals missing data: 3,594 User nodes are matched, but 3,518 have a non-null registration date. Cast one operand with `toFloat()` before dividing to calculate a percentage rather than an integer result. section 4.2
Listing 4.3 Counting the number of User nodes and their non-null values of registeredAt properties
MATCH (u:User)
RETURN count(*) AS numberOfRows,
count(u.registeredAt) AS numberOfUsersWithRegisteredAtDate
This query puts row counting and non-null property counting side by side, making the distinction visible in one result. section 4.2
Count what the query actually produces, not what the pattern seems to represent. A match of Tweet-to-User `MENTIONS` relationships produces one row per occurrence, so `count(u)` counts mentions rather than unique mentioned users. Use `count(distinct u)` when each user should contribute only once. Query cardinality—the number of incoming rows—also affects both the result and performance. section 4.3
Use aggregation placement deliberately in multi-step queries:
- Aggregate with `WITH count(...)` after a `MATCH` when a later match should run once instead of once per earlier row. section 4.5
- Count directly after each `OPTIONAL MATCH` when collecting separate categories, preventing intermediate rows from multiplying the final totals. section 4.5
- Count matched hashtag pairs to create a co-occurrence weight; filter duplicate pair orderings with `id(h1) < id(h2)` before ranking results. section 7.2
- Aggregate component members first, filter the component sizes, then count the remaining components. section 7.3.2
Count co-occurring hashtags
Match two tags attached to the same tweet, count the matches for each pair, sort by that count, and keep the top five. The resulting count becomes the relationship weight in a co-occurrence network; for example, `#ai` and `#nlp` co-occur 1,507 times. section 7.2




