> ## 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.

> Soma a diferença aritmética entre linhas consecutivas.

# deltaSum

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

Introduzido em: v21.3.0

Soma a diferença aritmética entre linhas consecutivas.
Se a diferença for negativa, ela será ignorada.

<Tip>
  Os dados devem estar ordenados para que esta função funcione corretamente.
  Se quiser usar esta função em uma [visão materializada](/pt-BR/reference/statements/create/view#materialized-view), provavelmente será melhor usar a função [`deltaSumTimestamp`](/pt-BR/reference/functions/aggregate-functions/deltaSumTimestamp).
</Tip>

Veja também:

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

**Sintaxe**

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

**Argumentos**

* `x1[, x2, ...]` — Um ou mais valores de entrada. [`Integer`](/pt-BR/reference/data-types/int-uint) ou [`Float`](/pt-BR/reference/data-types/float)

**Valor retornado**

Retorna a diferença aritmética acumulada dos valores de entrada. [`(U)Int*`](/pt-BR/reference/data-types/int-uint) ou [`Float*`](/pt-BR/reference/data-types/float)

**Exemplos**

**Uso básico com diferenças positivas**

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

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

**Valores mistos com diferenças negativas desconsideradas**

```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 │
└───────────────────────────────────────────────┘
```

**Valores de ponto flutuante**

```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 │
└─────────────────────────────────────┘
```

**Veja também**

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