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

> Calcula a média aritmética.

# avg

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

Introduzido em: v1.1.0

Calcula a média aritmética.

**Sintaxe**

```sql theme={null}
avg(x)
```

**Argumentos**

* `x` — Valores de entrada. [`(U)Int*`](/pt-BR/reference/data-types/int-uint) ou [`Float*`](/pt-BR/reference/data-types/float) ou [`Decimal`](/pt-BR/reference/data-types/decimal)

**Valor retornado**

Retorna a média aritmética ou `NaN` se o parâmetro de entrada `x` estiver vazio. [`Float64`](/pt-BR/reference/data-types/float)

**Exemplos**

**Uso básico**

```sql title=Query theme={null}
SELECT avg(x) FROM VALUES('x Int8', 0, 1, 2, 3, 4, 5);
```

```response title=Response theme={null}
┌─avg(x)─┐
│    2.5 │
└────────┘
```

**Uma tabela vazia retorna NaN**

```sql title=Query theme={null}
CREATE TABLE test (t UInt8) ENGINE = Memory;

SELECT avg(t) FROM test;
```

```response title=Response theme={null}
┌─avg(x)─┐
│    nan │
└────────┘
```
