ClickHouse/docs/zh/sql-reference/aggregate-functions/reference/initializeAggregation.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

39 lines
1.2 KiB
Markdown
Raw Normal View History

2021-02-02 12:00:41 +00:00
---
2022-08-26 19:07:59 +00:00
slug: /zh/sql-reference/aggregate-functions/reference/initializeAggregation
2022-04-10 23:08:18 +00:00
sidebar_position: 150
2021-02-02 12:00:41 +00:00
---
## initializeAggregation {#initializeaggregation}
2021-03-17 13:06:35 +00:00
初始化你输入行的聚合。用于后缀是 `State` 的函数。
用它来测试或处理 `AggregateFunction``AggregationgMergeTree` 类型的列。
2021-02-02 12:00:41 +00:00
2021-03-17 13:06:35 +00:00
**语法**
2021-02-02 12:00:41 +00:00
``` sql
2021-03-22 15:56:44 +00:00
initializeAggregation (aggregate_function, column_1, column_2)
2021-02-02 12:00:41 +00:00
```
2021-03-17 13:06:35 +00:00
**参数**
2021-02-02 12:00:41 +00:00
2021-03-17 13:06:35 +00:00
- `aggregate_function` — 聚合函数名。 这个函数的状态 — 正创建的。[String](../../../sql-reference/data-types/string.md#string)。
- `column_n` — 将其转换为函数的参数的列。[String](../../../sql-reference/data-types/string.md#string)。
2021-02-02 12:00:41 +00:00
2021-03-17 13:06:35 +00:00
**返回值**
2021-02-02 12:00:41 +00:00
2021-03-17 13:06:35 +00:00
返回输入行的聚合结果。返回类型将与 `initializeAgregation` 用作第一个参数的函数的返回类型相同。
例如,对于后缀为 `State` 的函数,返回类型将是 `AggregateFunction`
2021-02-02 12:00:41 +00:00
2021-03-17 13:06:35 +00:00
**示例**
2021-02-02 12:00:41 +00:00
2021-03-17 13:06:35 +00:00
查询:
2021-02-02 12:00:41 +00:00
```sql
SELECT uniqMerge(state) FROM (SELECT initializeAggregation('uniqState', number % 3) AS state FROM system.numbers LIMIT 10000);
```
2021-03-17 13:06:35 +00:00
结果:
2021-02-02 12:00:41 +00:00
┌─uniqMerge(state)─┐
│ 3 │
└──────────────────┘