groupArrayMovingAvg
Calculates the moving average of input values.
groupArrayMovingAvg(numbers_for_summing)
groupArrayMovingAvg(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.
The function uses rounding towards zero. It truncates the decimal places insignificant for the resulting data type.
Example
The sample table b
:
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
groupArrayMovingAvg(int) AS I,
groupArrayMovingAvg(float) AS F,
groupArrayMovingAvg(dec) AS D
FROM t
ββIββββββββββ¬βFββββββββββββββββββββββββββββββββββββ¬βDββββββββββββββββββββββ
β [0,0,1,3] β [0.275,0.82500005,1.9250001,3.8675] β [0.27,0.82,1.92,3.86] β
βββββββββββββ΄ββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββ
SELECT
groupArrayMovingAvg(2)(int) AS I,
groupArrayMovingAvg(2)(float) AS F,
groupArrayMovingAvg(2)(dec) AS D
FROM t
ββIββββββββββ¬βFβββββββββββββββββββββββββββββββββ¬βDββββββββββββββββββββββ
β [0,1,3,5] β [0.55,1.6500001,3.3000002,6.085] β [0.55,1.65,3.30,6.08] β
βββββββββββββ΄βββββββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββ