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

70 lines
1.4 KiB
Markdown
Raw Normal View History

2021-03-19 07:39:10 +00:00
---
toc_priority: 141
---
# deltaSum {#agg_functions-deltasum}
2021-03-23 13:10:26 +00:00
计算连续行之间的差值和。如果差值为负,则忽略。
2021-03-19 07:39:10 +00:00
**语法**
``` sql
deltaSum(value)
```
2021-03-23 13:10:26 +00:00
**参数**
- `value` — 必须是 [整型](../../data-types/int-uint.md) 或者 [浮点型](../../data-types/float.md) 。
**返回值**
- `Integer` or `Float` 型的算术差值和。
**示例**
查询:
``` sql
SELECT deltaSum(arrayJoin([1, 2, 3]));
```
结果:
``` text
┌─deltaSum(arrayJoin([1, 2, 3]))─┐
│ 2 │
└────────────────────────────────┘
```
2021-03-19 07:39:10 +00:00
2021-03-23 13:10:26 +00:00
查询:
2021-03-19 07:39:10 +00:00
2021-03-23 13:10:26 +00:00
``` sql
SELECT deltaSum(arrayJoin([1, 2, 3, 0, 3, 4, 2, 3]));
2021-03-19 07:39:10 +00:00
```
2021-03-23 13:10:26 +00:00
结果:
``` text
┌─deltaSum(arrayJoin([1, 2, 3, 0, 3, 4, 2, 3]))─┐
│ 7 │
└───────────────────────────────────────────────┘
```
查询:
``` sql
SELECT deltaSum(arrayJoin([2.25, 3, 4.5]));
```
结果:
``` text
┌─deltaSum(arrayJoin([2.25, 3, 4.5]))─┐
│ 2.25 │
└─────────────────────────────────────┘
```
2021-03-24 15:46:03 +00:00
**参见**
2021-03-23 13:10:26 +00:00
- [runningDifference](../../functions/other-functions.md#other_functions-runningdifference)