An aggregate function performs a calculation on a set of values and returns a single scalar value.
All aggregate functions support the use of the set quantifier DISTINCT to deduplicate values before aggregation.
Rows containing null values are ignored by all aggregate functions, except count(*).

GQLINSERT (p1:Paper {_id:'P1', title:'Efficient Graph Search', score:6, author:'Alex'}), (p2:Paper {_id:'P2', title:'Optimizing Queries', score:9, author:'Alex'}), (p3:Paper {_id:'P3', title:'Path Patterns', score:7, author:'Zack'}), (p1)-[:Cites {weight:2}]->(p2), (p2)-[:Cites {weight:1}]->(p3)
Collects a set of values into a list. collect() is an alias for collect_list().
| Syntax | collect_list(<values>) | ||
| Arguments | Name | Type | Description |
<values> | Any | The target values | |
| Return Type | LIST | ||
GQLMATCH (n) RETURN collect_list(n.title)
Result:
| collect_list(n.title) |
|---|
| ["Optimizing Queries","Efficient Graph Search","Path Patterns"] |
Returns the number of rows in the input.
| Syntax | count(<values>) | ||
| Arguments | Name | Type | Description |
<values> | Any | The target values | |
| Return Type | UINT | ||
GQLMATCH (n) RETURN count(n)
Result: 3
count(*) returns the number of rows in the intermediate result table.
Comparing the following two queries, the null values are only considered when using count(*):
GQLFOR item IN [1, "a", "2", "b3", null] RETURN count(item)
Result: 4
GQLFOR item IN [1, "a", "2", "b3", null] RETURN count(*)
Result: 5
You can include the set quantifier DISTINCT in count() to return the number of distinct rows in the input.
GQLFOR item IN [1, 1, "a", "2", "b3", null] RETURN count(DISTINCT item)
Result: 4
Returns the maximum value in a set of values.
| Syntax | max(<values>) | ||
| Arguments | Name | Type | Description |
<values> | Any | The target values | |
| Return Type | Numeric | ||
GQLMATCH (n) RETURN max(n.score)
Result: 9
Returns the minimum value in a set of values.
| Syntax | min(<values>) | ||
| Arguments | Name | Type | Description |
<values> | Any | The target values | |
| Return Type | Numeric | ||
GQLMATCH (n) RETURN min(n.score)
Result: 6
Computes the average of a set of numeric values.
| Syntax | avg(<values>) | ||
| Arguments | Name | Type | Description |
<values> | Numeric | The target values | |
| Return Type | DOUBLE | ||
GQLMATCH (n) RETURN avg(n.score)
Result: 7.333333333333333
Computes the sum of a set of numeric values.
| Syntax | sum(<values>) | ||
| Arguments | Name | Type | Description |
<values> | Numeric | The target values | |
| Return Type | DOUBLE | ||
GQLMATCH (n) RETURN sum(n.score)
Result: 22
Computes the continuous percentile value over a set of numeric values.
| Syntax | percentile_cont(<values>, <percentile>) | ||
| Arguments | Name | Type | Description |
<values> | Numeric | The target values | |
<percentile> | Numeric | Number between 0.0 and 1.0 | |
| Return Type | DOUBLE | ||
percentile_cont() is computed using the following steps:
p = percentile × (n − 1) + 1, where n is the number of non-null values.p is an integer, the corresponding value at that position is the percentile value.p is a decimal between two integers p1 and p2 (p1 < p < p2), interpolate between the value v1 at position p1 and the value v2 at position p2 to compute the percentile value as v1 + (p - p1) × (v2 - v1).GQLFOR item IN [3, 9, 4, 7, 6] RETURN percentile_cont(item, 0.4)
Result: 5.2
GQLFOR item IN [3, 9, 4, 7, 6] RETURN percentile_cont(item, 0.5)
Result: 6
Computes the discrete percentile value over a set of numeric values.
| Syntax | percentile_disc(<values>, <percentile>) | ||
| Arguments | Name | Type | Description |
<values> | Numeric | The target values | |
<percentile> | Numeric | Number between 0.0 and 1.0 | |
| Return Type | DOUBLE | ||
percentile_disc() is computed using the following steps:
p = ceil(percentile × n), where n is the number of non-null values.p is selected as the percentile value.GQLFOR item IN [3, 9, 4, 7, 6] RETURN percentile_disc(item, 0.4)
Result: 4
GQLFOR item IN [3, 9, 4, 7, 6] RETURN percentile_disc(item, 0.5)
Result: 6
Computes the population standard deviation of a set of numeric values.
| Syntax | stddev_pop(<values>) | ||
| Arguments | Name | Type | Description |
<values> | Numeric | The target values | |
| Return Type | Numeric | ||
GQLMATCH (n) RETURN stddev_pop(n.score)
Result: 1.247219128924647
Computes the sample standard deviation of a set of numeric values.
| Syntax | stddev_samp(<values>) | ||
| Arguments | Name | Type | Description |
<values> | Numeric | The target values | |
| Return Type | DOUBLE | ||
GQLMATCH (n) RETURN stddev_samp(n.score)
Result: 1.5275252316519468