Documentation Index
Fetch the complete documentation index at: https://private-7c7dfe99-page-updates.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Aggregate functions
Aggregate functions work in the normal way as expected by database experts. ClickHouse also supports:- Parametric aggregate functions, which accept other parameters in addition to columns.
- Combinators, which change the behavior of aggregate functions.
NULL processing
During aggregation, allNULL arguments are skipped. If the aggregation has several arguments it will ignore any row in which one or more of them are NULL.
There is an exception to this rule, which are the functions first_value, last_value and their aliases (any and anyLast respectively) when followed by the modifier RESPECT NULLS. For example, FIRST_VALUE(b) RESPECT NULLS.
Examples:
Consider this table:
y column:
groupArray function to create an array from the y column:
groupArray does not include NULL in the resulting array.
You can use COALESCE to change NULL into a value that makes sense in your use case. For example: avg(COALESCE(column, 0)) with use the column value in the aggregation or zero if NULL:
Tuple that contains only a NULL value is not NULL, so the aggregate functions won’t skip that row because of that NULL value.
count without parameters (count()) or with constant ones (count(1)) will count all rows in the block (independently of the value of the GROUP BY column as it’s not an argument), while count(column) will only return the number of rows where column is not NULL.
RESPECT NULLS where we can see that NULL inputs are respected and it will return the first value read, whether it’s NULL or not: