Skip to main content

Cypher Functions

Reference for supported Cypher aggregation functions.

COUNT

Count rows or values.

COUNT(*)

MATCH (p:Person) RETURN COUNT(*)

COUNT(expression)

MATCH (p:Person) RETURN COUNT(p.age)

COUNT(DISTINCT)

MATCH (p:Person) RETURN COUNT(DISTINCT p.city)

AVG

Average of numeric values.

MATCH (p:Person) RETURN AVG(p.age)

AVG with DISTINCT

MATCH (o:Order) RETURN AVG(DISTINCT o.discount)

SUM

Sum of numeric values.

MATCH (o:Order) RETURN SUM(o.amount)

MIN

Minimum value.

MATCH (p:Person) RETURN MIN(p.age)

MAX

Maximum value.

MATCH (p:Person) RETURN MAX(p.age)

COLLECT

Collect values into an array.

MATCH (p:Person) RETURN COLLECT(p.name)

With DISTINCT

MATCH (p:Person) RETURN COLLECT(DISTINCT p.city)

Using Aliases

Combine with aliases for cleaner output:

MATCH (p:Person)
RETURN p.city,
COUNT(*) AS total,
AVG(p.age) AS avgAge,
MIN(p.age) AS minAge,
MAX(p.age) AS maxAge
ORDER BY total DESC