> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> 计算连续行之间算术差值的总和。

# deltaSum

<div id="deltaSum">
  ## deltaSum
</div>

版本引入：v21.3.0

对连续行之间的算术差值进行求和。
如果差值为负，则会被忽略。

<Tip>
  要使此函数正常工作，底层数据必须已排序。
  如果你想在 [materialized view](/zh/reference/statements/create/view#materialized-view) 中使用此函数，通常应改用 [`deltaSumTimestamp`](/zh/reference/functions/aggregate-functions/deltaSumTimestamp) 函数。
</Tip>

另请参见：

* [`runningDifference`](/zh/reference/functions/regular-functions/other-functions#runningDifference)

**语法**

```sql theme={null}
deltaSum(x1[, x2, ...])
```

**参数**

* `x1[, x2, ...]` — 一个或多个输入值。[`Integer`](/zh/reference/data-types/int-uint) 或 [`Float`](/zh/reference/data-types/float)

**返回值**

返回输入值中增长部分的算术差值。[`(U)Int*`](/zh/reference/data-types/int-uint) 或 [`Float*`](/zh/reference/data-types/float)

**示例**

**正向差值的基本用法**

```sql title=Query theme={null}
SELECT deltaSum(arrayJoin([1, 2, 3]))
```

```response title=Response theme={null}
┌─deltaSum(arrayJoin([1, 2, 3]))─┐
│                              2 │
└────────────────────────────────┘
```

**混合值 (忽略负差值) **

```sql title=Query theme={null}
SELECT deltaSum(arrayJoin([1, 2, 3, 0, 3, 4, 2, 3]))
```

```response title=Response theme={null}
┌─deltaSum(arrayJoin([1, 2, 3, 0, 3, 4, 2, 3]))─┐
│                                             7 │
└───────────────────────────────────────────────┘
```

**浮点值**

```sql title=Query theme={null}
SELECT deltaSum(arrayJoin([2.25, 3, 4.5]))
```

```response title=Response theme={null}
┌─deltaSum(arrayJoin([2.25, 3, 4.5]))─┐
│                                2.25 │
└─────────────────────────────────────┘
```

**另请参阅**

* [`runningDifference`](/zh/reference/functions/regular-functions/other-functions#runningDifference)
