ClickHouse/docs/en/sql-reference/aggregate-functions/reference/deltasum.md

1.9 KiB

toc_priority
141

deltaSum

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

Syntax

<<<<<<< HEAD Note that the underlying data must be sorted in order 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.

Example:

select deltaSum(arrayJoin([1, 2, 3]));                  -- => 2
select deltaSum(arrayJoin([1, 2, 3, 0, 3, 4, 2, 3]));   -- => 7
select deltaSum(arrayJoin([2.25, 3, 4.5]));             -- => 2.25
=======
``` sql
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 │
└────────────────────────────────┘
>>>>>>> origin

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