Skip to main content

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
β”Œβ”€sum(y)─┐
β”‚ 7 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜

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

SELECT groupArray(y) FROM t_null_big
β”Œβ”€groupArray(y)─┐
β”‚ [2,2,3] β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

groupArray does not include NULL in the resulting array.