Relational Data - Aggregate Functions - Reference - Deltasum

From FojiSoft Docs
Revision as of 18:43, 28 August 2024 by Chris.Hansen (talk | contribs) (Import ClickHouse Docs: Wed Aug 28 2024 14:43:41 GMT-0400 (Eastern Daylight Time))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

The underlying data must be sorted for this function to work properly. If you would like to use this function in a materialized view, you most likely want to use the deltaSumTimestamp method instead.


Syntax

deltaSum(value)

Arguments

Returned value

  • A gained arithmetic difference of the Integer or Float type.

Examples

Query:

SELECT deltaSum(arrayJoin([1, 2, 3]));

Result:

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

Query:

SELECT deltaSum(arrayJoin([1, 2, 3, 0, 3, 4, 2, 3]));

Result:

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

Query:

SELECT deltaSum(arrayJoin([2.25, 3, 4.5]));

Result:

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

See Also