2021-02-02 12:00:41 +00:00
|
|
|
---
|
2022-08-26 19:07:59 +00:00
|
|
|
slug: /zh/sql-reference/aggregate-functions/reference/grouparraymovingsum
|
2022-04-10 23:08:18 +00:00
|
|
|
sidebar_position: 113
|
2021-02-02 12:00:41 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
# groupArrayMovingSum {#agg_function-grouparraymovingsum}
|
|
|
|
|
2021-02-04 15:34:04 +00:00
|
|
|
|
|
|
|
计算输入值的移动和。
|
|
|
|
|
|
|
|
**语法**
|
2021-02-02 12:00:41 +00:00
|
|
|
|
|
|
|
``` sql
|
|
|
|
groupArrayMovingSum(numbers_for_summing)
|
|
|
|
groupArrayMovingSum(window_size)(numbers_for_summing)
|
|
|
|
```
|
|
|
|
|
2021-02-04 15:34:04 +00:00
|
|
|
该函数可以将窗口大小作为参数。 如果未指定,则该函数的窗口大小等于列中的行数。
|
2021-02-02 12:00:41 +00:00
|
|
|
|
2021-02-04 15:34:04 +00:00
|
|
|
**参数**
|
2021-02-02 12:00:41 +00:00
|
|
|
|
2021-02-05 15:50:14 +00:00
|
|
|
- `numbers_for_summing` — [表达式](../../../sql-reference/syntax.md#syntax-expressions) 生成数值数据类型值。
|
2021-02-04 15:34:04 +00:00
|
|
|
- `window_size` — 窗口大小。
|
2021-02-02 12:00:41 +00:00
|
|
|
|
2021-02-04 15:34:04 +00:00
|
|
|
**返回值**
|
2021-02-02 12:00:41 +00:00
|
|
|
|
2021-02-04 15:34:04 +00:00
|
|
|
- 与输入数据大小相同的数组。
|
|
|
|
对于输入数据类型是[Decimal](../../../sql-reference/data-types/decimal.md) 数组元素类型是 `Decimal128` 。
|
|
|
|
对于其他的数值类型, 获取其对应的 `NearestFieldType` 。
|
2021-02-02 12:00:41 +00:00
|
|
|
|
2021-02-04 15:34:04 +00:00
|
|
|
**示例**
|
2021-02-02 12:00:41 +00:00
|
|
|
|
2021-02-04 15:34:04 +00:00
|
|
|
样表:
|
2021-02-02 12:00:41 +00:00
|
|
|
|
|
|
|
``` sql
|
|
|
|
CREATE TABLE t
|
|
|
|
(
|
|
|
|
`int` UInt8,
|
|
|
|
`float` Float32,
|
|
|
|
`dec` Decimal32(2)
|
|
|
|
)
|
|
|
|
ENGINE = TinyLog
|
|
|
|
```
|
|
|
|
|
|
|
|
``` text
|
|
|
|
┌─int─┬─float─┬──dec─┐
|
|
|
|
│ 1 │ 1.1 │ 1.10 │
|
|
|
|
│ 2 │ 2.2 │ 2.20 │
|
|
|
|
│ 4 │ 4.4 │ 4.40 │
|
|
|
|
│ 7 │ 7.77 │ 7.77 │
|
|
|
|
└─────┴───────┴──────┘
|
|
|
|
```
|
|
|
|
|
2021-02-04 15:34:04 +00:00
|
|
|
查询:
|
2021-02-02 12:00:41 +00:00
|
|
|
|
|
|
|
``` sql
|
|
|
|
SELECT
|
|
|
|
groupArrayMovingSum(int) AS I,
|
|
|
|
groupArrayMovingSum(float) AS F,
|
|
|
|
groupArrayMovingSum(dec) AS D
|
|
|
|
FROM t
|
|
|
|
```
|
|
|
|
|
|
|
|
``` text
|
|
|
|
┌─I──────────┬─F───────────────────────────────┬─D──────────────────────┐
|
|
|
|
│ [1,3,7,14] │ [1.1,3.3000002,7.7000003,15.47] │ [1.10,3.30,7.70,15.47] │
|
|
|
|
└────────────┴─────────────────────────────────┴────────────────────────┘
|
|
|
|
```
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
SELECT
|
|
|
|
groupArrayMovingSum(2)(int) AS I,
|
|
|
|
groupArrayMovingSum(2)(float) AS F,
|
|
|
|
groupArrayMovingSum(2)(dec) AS D
|
|
|
|
FROM t
|
|
|
|
```
|
|
|
|
|
|
|
|
``` text
|
|
|
|
┌─I──────────┬─F───────────────────────────────┬─D──────────────────────┐
|
|
|
|
│ [1,3,6,11] │ [1.1,3.3000002,6.6000004,12.17] │ [1.10,3.30,6.60,12.17] │
|
|
|
|
└────────────┴─────────────────────────────────┴────────────────────────┘
|
|
|
|
```
|