ClickHouse/docs/en/query_language/agg_functions/index.md
ogorbacheva 06aa03f1a7 Doc fixes: remove all anchors <a> (#3897)
* Doc fixes: rm anchors <a>

* Doc fixes: rm anchors <a>

* Doc fixes: fix links

* Doc fixes: fix the links
2018-12-21 22:23:55 +03:00

1.6 KiB

Aggregate functions

Aggregate functions work in the normal way as expected by database experts.

ClickHouse also supports:

NULL processing

During aggregation, all NULLs are skipped.

Examples:

Consider this table:

┌─x─┬────y─┐
│ 1 │    2 │
│ 2 │ ᴺᵁᴸᴸ │
│ 3 │    2 │
│ 3 │    3 │
│ 3 │ ᴺᵁᴸᴸ │
└───┴──────┘

Let's say you need to total the values in the y column:

:) SELECT sum(y) FROM t_null_big

SELECT sum(y)
FROM t_null_big

┌─sum(y)─┐
│      7 │
└────────┘

1 rows in set. Elapsed: 0.002 sec.

The sum function interprets NULL as 0. In particular, this means that if the function receives input of a selection where all the values are NULL, then the result will be 0, not NULL.

Now you can use the groupArray function to create an array from the y column:

:) SELECT groupArray(y) FROM t_null_big

SELECT groupArray(y)
FROM t_null_big

┌─groupArray(y)─┐
│ [2,2,3]       │
└───────────────┘

1 rows in set. Elapsed: 0.002 sec.

groupArray does not include NULL in the resulting array.

Original article