Skip to content
ClickHouse Docs
ClickHouse DocsClickHouse Docs

deltaSum

deltaSum

Introduced in: v21.3.0

Sums the arithmetic difference between consecutive rows. If the difference is negative, it is ignored.

See also:

Syntax

deltaSum(x1[, x2, ...])

Arguments

  • x1[, x2, ...] — One or more input values. Integer or Float

Returned value

Returns a gained arithmetic difference of the input values. (U)Int* or Float*

Examples

Basic usage with positive differences

SELECT deltaSum(arrayJoin([1, 2, 3]))
┌─deltaSum(arrayJoin([1, 2, 3]))─┐
│                              2 │
└────────────────────────────────┘

Mixed values with negative differences ignored

SELECT deltaSum(arrayJoin([1, 2, 3, 0, 3, 4, 2, 3]))
┌─deltaSum(arrayJoin([1, 2, 3, 0, 3, 4, 2, 3]))─┐
│                                             7 │
└───────────────────────────────────────────────┘

Float values

SELECT deltaSum(arrayJoin([2.25, 3, 4.5]))
┌─deltaSum(arrayJoin([2.25, 3., 4.5]))─┐
│                                 2.25 │
└──────────────────────────────────────┘

See also

Navigation