2020-06-18 08:24:31 +00:00
---
2022-08-28 14:53:34 +00:00
slug: /en/sql-reference/aggregate-functions/reference/grouparraymovingsum
2022-04-09 13:29:05 +00:00
sidebar_position: 113
2020-06-18 08:24:31 +00:00
---
2022-06-02 10:55:18 +00:00
# groupArrayMovingSum
2020-06-18 08:24:31 +00:00
Calculates the moving sum of input values.
``` sql
groupArrayMovingSum(numbers_for_summing)
groupArrayMovingSum(window_size)(numbers_for_summing)
```
The function can take the window size as a parameter. If left unspecified, the function takes the window size equal to the number of rows in the column.
2021-02-15 21:33:53 +00:00
**Arguments**
2020-06-18 08:24:31 +00:00
- `numbers_for_summing` — [Expression ](../../../sql-reference/syntax.md#syntax-expressions ) resulting in a numeric data type value.
- `window_size` — Size of the calculation window.
**Returned values**
- Array of the same size and type as the input data.
**Example**
The sample table:
``` 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 │
└─────┴───────┴──────┘
```
The queries:
``` 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] │
└────────────┴─────────────────────────────────┴────────────────────────┘
```