groupArrayMovingSum

Calculates the moving sum of input values.

  1. groupArrayMovingSum(numbers_for_summing)
  2. 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.

Parameters

  • numbers_for_summingExpression 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:

  1. CREATE TABLE t
  2. (
  3. `int` UInt8,
  4. `float` Float32,
  5. `dec` Decimal32(2)
  6. )
  7. ENGINE = TinyLog
  1. ┌─int─┬─float─┬──dec─┐
  2. 1 1.1 1.10
  3. 2 2.2 2.20
  4. 4 4.4 4.40
  5. 7 7.77 7.77
  6. └─────┴───────┴──────┘

The queries:

  1. SELECT
  2. groupArrayMovingSum(int) AS I,
  3. groupArrayMovingSum(float) AS F,
  4. groupArrayMovingSum(dec) AS D
  5. FROM t
  1. ┌─I──────────┬─F───────────────────────────────┬─D──────────────────────┐
  2. [1,3,7,14] [1.1,3.3000002,7.7000003,15.47] [1.10,3.30,7.70,15.47]
  3. └────────────┴─────────────────────────────────┴────────────────────────┘
  1. SELECT
  2. groupArrayMovingSum(2)(int) AS I,
  3. groupArrayMovingSum(2)(float) AS F,
  4. groupArrayMovingSum(2)(dec) AS D
  5. FROM t
  1. ┌─I──────────┬─F───────────────────────────────┬─D──────────────────────┐
  2. [1,3,6,11] [1.1,3.3000002,6.6000004,12.17] [1.10,3.30,6.60,12.17]
  3. └────────────┴─────────────────────────────────┴────────────────────────┘