# avg (/docs/reference/sql/aggregate-functions/avg)



This page describes the RawTree engine binary used to generate this reference. It does not define Query API support. Descriptions retain upstream ClickHouse terminology. See [SQL interface scope](/docs/reference/clickhouse-compatibility#service-interfaces).

Calculates the arithmetic mean.

**Syntax**

```sql
avg(x)
```

**Arguments**

* `x` — Input values. [`(U)Int*`](/reference/data-types/int-uint) or [`Float*`](/reference/data-types/float) or [`Decimal`](/reference/data-types/decimal)

**Returned value**

Returns the arithmetic mean, otherwise returns `NaN` if the input parameter `x` is empty. [`Float64`](/reference/data-types/float)

**Examples**

**Basic usage**

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

```text title=Response
┌─avg(x)─┐
│    2.5 │
└────────┘
```

**Empty table returns NaN**

```sql title=Query
CREATE TABLE test (t UInt8) ENGINE = Memory;

SELECT avg(t) FROM test;
```

```text title=Response
┌─avg(x)─┐
│    nan │
└────────┘
```

*Introduced in version 1.1.0.*
