groupArrayMovingSum
Calculates the moving sum of input values.
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.
Arguments
numbers_for_summing
β Expression 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:
CREATE TABLE t
(
`int` UInt8,
`float` Float32,
`dec` Decimal32(2)
)
ENGINE = TinyLog
ββ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:
SELECT
groupArrayMovingSum(int) AS I,
groupArrayMovingSum(float) AS F,
groupArrayMovingSum(dec) AS D
FROM t
ββIβββββββββββ¬βFββββββββββββββββββββββββββββββββ¬βDβββββββββββββββββββββββ
β [1,3,7,14] β [1.1,3.3000002,7.7000003,15.47] β [1.10,3.30,7.70,15.47] β
ββββββββββββββ΄ββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββ
SELECT
groupArrayMovingSum(2)(int) AS I,
groupArrayMovingSum(2)(float) AS F,
groupArrayMovingSum(2)(dec) AS D
FROM t
ββIβββββββββββ¬βFββββββββββββββββββββββββββββββββ¬βDβββββββββββββββββββββββ
β [1,3,6,11] β [1.1,3.3000002,6.6000004,12.17] β [1.10,3.30,6.60,12.17] β
ββββββββββββββ΄ββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββ