ClickHouse/docs/en/sql-reference/aggregate-functions/index.md
2022-08-28 10:53:34 -04:00

62 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
slug: /en/sql-reference/aggregate-functions/
sidebar_label: Aggregate Functions
sidebar_position: 33
---
# Aggregate Functions
Aggregate functions work in the [normal](http://www.sql-tutorial.com/sql-aggregate-functions-sql-tutorial) way as expected by database experts.
ClickHouse also supports:
- [Parametric aggregate functions](../../sql-reference/aggregate-functions/parametric-functions.md#aggregate_functions_parametric), which accept other parameters in addition to columns.
- [Combinators](../../sql-reference/aggregate-functions/combinators.md#aggregate_functions_combinators), which change the behavior of aggregate functions.
## NULL Processing
During aggregation, all `NULL`s are skipped.
**Examples:**
Consider this table:
``` text
┌─x─┬────y─┐
│ 1 │ 2 │
│ 2 │ ᴺᵁᴸᴸ │
│ 3 │ 2 │
│ 3 │ 3 │
│ 3 │ ᴺᵁᴸᴸ │
└───┴──────┘
```
Lets say you need to total the values in the `y` column:
``` sql
SELECT sum(y) FROM t_null_big
```
```text
┌─sum(y)─┐
│ 7 │
└────────┘
```
Now you can use the `groupArray` function to create an array from the `y` column:
``` sql
SELECT groupArray(y) FROM t_null_big
```
``` text
┌─groupArray(y)─┐
│ [2,2,3] │
└───────────────┘
```
`groupArray` does not include `NULL` in the resulting array.