2021-02-04 03:49:28 +00:00
|
|
|
---
|
|
|
|
toc_priority: 141
|
|
|
|
---
|
|
|
|
|
|
|
|
# deltaSum {#agg_functions-deltasum}
|
|
|
|
|
2021-03-23 08:07:18 +00:00
|
|
|
Sums the arithmetic difference between consecutive rows. If the difference is negative, it is ignored.
|
2021-02-04 03:49:28 +00:00
|
|
|
|
2021-03-17 17:42:53 +00:00
|
|
|
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
|
2021-03-23 19:27:38 +00:00
|
|
|
[deltaSumTimestamp](deltasumtimestamp.md) method instead.
|
2021-03-17 17:42:53 +00:00
|
|
|
|
2021-03-23 19:27:38 +00:00
|
|
|
**Syntax**
|
2021-02-04 03:49:28 +00:00
|
|
|
|
2021-03-10 18:08:30 +00:00
|
|
|
``` sql
|
|
|
|
deltaSum(value)
|
2021-02-04 03:49:28 +00:00
|
|
|
```
|
|
|
|
|
2021-03-18 06:30:41 +00:00
|
|
|
**Arguments**
|
2021-03-10 18:08:30 +00:00
|
|
|
|
|
|
|
- `value` — Input values, must be [Integer](../../data-types/int-uint.md) or [Float](../../data-types/float.md) type.
|
|
|
|
|
|
|
|
**Returned value**
|
|
|
|
|
2021-03-18 06:30:36 +00:00
|
|
|
- A gained arithmetic difference of the `Integer` or `Float` type.
|
2021-03-10 18:08:30 +00:00
|
|
|
|
|
|
|
**Examples**
|
|
|
|
|
|
|
|
Query:
|
|
|
|
|
|
|
|
``` sql
|
2021-03-18 13:16:15 +00:00
|
|
|
SELECT deltaSum(arrayJoin([1, 2, 3]));
|
2021-03-10 18:08:30 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Result:
|
|
|
|
|
|
|
|
``` text
|
|
|
|
┌─deltaSum(arrayJoin([1, 2, 3]))─┐
|
|
|
|
│ 2 │
|
|
|
|
└────────────────────────────────┘
|
|
|
|
```
|
|
|
|
|
|
|
|
Query:
|
|
|
|
|
|
|
|
``` sql
|
2021-03-18 13:16:15 +00:00
|
|
|
SELECT deltaSum(arrayJoin([1, 2, 3, 0, 3, 4, 2, 3]));
|
2021-03-10 18:08:30 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Result:
|
|
|
|
|
|
|
|
``` text
|
|
|
|
┌─deltaSum(arrayJoin([1, 2, 3, 0, 3, 4, 2, 3]))─┐
|
|
|
|
│ 7 │
|
|
|
|
└───────────────────────────────────────────────┘
|
|
|
|
```
|
|
|
|
|
|
|
|
Query:
|
|
|
|
|
|
|
|
``` sql
|
2021-03-18 13:16:15 +00:00
|
|
|
SELECT deltaSum(arrayJoin([2.25, 3, 4.5]));
|
2021-03-10 18:08:30 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Result:
|
|
|
|
|
|
|
|
``` text
|
|
|
|
┌─deltaSum(arrayJoin([2.25, 3, 4.5]))─┐
|
|
|
|
│ 2.25 │
|
|
|
|
└─────────────────────────────────────┘
|
|
|
|
```
|
|
|
|
|
2021-03-18 13:16:15 +00:00
|
|
|
## See Also {#see-also}
|
|
|
|
|
2021-03-23 08:07:18 +00:00
|
|
|
- [runningDifference](../../functions/other-functions.md#other_functions-runningdifference)
|