Skip to Content
CypherFunctionsAggregate functions

Aggregation Functions

count()

Signature:

count(*) -> BIGINT

Returns the number of input rows.

count(x: T) -> BIGINT

Returns the count of non-null input values.

Example:

MATCH (n:Person) RETURN count(*) AS total_people; MATCH (n:Person) RETURN count(n.age) AS known_ages;

sum()

Signature:

sum(x: NUMERIC) -> BIGINT | FLOAT | DOUBLE

Returns the sum of all input values.

Example:

MATCH (n:Transaction) RETURN sum(n.amount) AS total_amount;

min()

Signature:

min(x: T) -> T

Returns the minimum value among all input values, ignoring nulls. x must not contain nulls if it is a complex type.

Example:

MATCH (n:Product) RETURN min(n.price) AS lowest_price;

max()

Signature:

max(x: T) -> T

Returns the maximum value among all input values, ignoring nulls. x must not contain nulls if it is a complex type.

Example:

MATCH (n:Product) RETURN max(n.price) AS highest_price;

avg()

Signature:

avg(x: NUMERIC) -> FLOAT | DOUBLE

Returns the average (arithmetic mean) of all non-null input values.

Example:

MATCH (n:Student) RETURN avg(n.grade) AS average_grade;

variance()

Signature:

variance(x: NUMERIC) -> Double

Returns the sample variance of all input values.

Example:

MATCH (n:Employee) RETURN variance(n.salary) AS salary_variance;

stddev()

Signature:

stddev(x: NUMERIC) -> Double

Returns the sample standard deviation of all input values.

Example:

MATCH (n:Employee) RETURN stddev(n.salary) AS salary_stddev;

count_if()

Signature:

count_if(x: BOOLEAN) -> BIGINT

Returns the count of TRUE input values, equivalent to count(CASE WHEN x THEN 1 END).

Example:

MATCH (n:Person) RETURN count_if(n.active) AS active_count;

set_agg()

Signature:

set_agg(x: T) -> ARRAY<T>

Returns a list created from distinct input x elements. For complex types, x must not contain nulls.

Example:

MATCH (n:Person) RETURN set_agg(n.city) AS unique_cities;

array_agg()

Signature:

array_agg(x: T) -> ARRAY<T>

Returns a list created from the input x elements.

Example:

MATCH (n:Person) RETURN array_agg(n.name) AS names;
Last updated on