> ## 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](/ja/reference/statements/create/view#materialized-view) で使用する場合は、代わりに [`deltaSumTimestamp`](/ja/reference/functions/aggregate-functions/deltaSumTimestamp) 関数を使用することをおすすめします。
</Tip>

関連項目:

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

**構文**

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

**引数**

* `x1[, x2, ...]` — 1 つ以上の入力値。[`Integer`](/ja/reference/data-types/int-uint) または [`Float`](/ja/reference/data-types/float)

**戻り値**

入力値の増加分の算術差を返します。[`(U)Int*`](/ja/reference/data-types/int-uint) または [`Float*`](/ja/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`](/ja/reference/functions/regular-functions/other-functions#runningDifference)
