2020-06-18 08:24:31 +00:00
---
toc_priority: 5
---
# avg {#agg_function-avg}
2020-10-30 16:17:57 +00:00
Calculates the arithmetic mean.
**Syntax**
``` sql
2021-02-02 12:26:36 +00:00
avg(x)
2020-10-30 16:17:57 +00:00
```
2021-02-15 21:33:53 +00:00
**Arguments**
2020-10-30 16:17:57 +00:00
2021-03-05 14:58:08 +00:00
- `x` — input values, must be [Integer ](../../../sql-reference/data-types/int-uint.md ), [Float ](../../../sql-reference/data-types/float.md ), or [Decimal ](../../../sql-reference/data-types/decimal.md ).
2020-10-30 16:17:57 +00:00
**Returned value**
2021-03-02 22:59:12 +00:00
- The arithmetic mean, always as [Float64 ](../../../sql-reference/data-types/float.md ).
- `NaN` if the input parameter `x` is empty.
2020-10-30 16:17:57 +00:00
**Example**
Query:
``` sql
2021-03-02 22:46:37 +00:00
SELECT avg(x) FROM values('x Int8', 0, 1, 2, 3, 4, 5);
2020-10-30 16:17:57 +00:00
```
Result:
``` text
┌─avg(x)─┐
│ 2.5 │
└────────┘
```
**Example**
2021-03-02 22:59:12 +00:00
Create a temp table:
2020-10-30 16:17:57 +00:00
Query:
``` sql
CREATE table test (t UInt8) ENGINE = Memory;
2021-03-02 22:59:12 +00:00
```
2021-07-29 15:20:55 +00:00
Get the arithmetic mean:
2021-03-02 22:59:12 +00:00
Query:
```
SELECT avg(t) FROM test;
2020-10-30 16:17:57 +00:00
```
Result:
``` text
┌─avg(x)─┐
2020-10-30 18:08:33 +00:00
│ nan │
2020-10-30 16:17:57 +00:00
└────────┘
```
2021-03-02 22:59:12 +00:00
2021-03-12 08:49:38 +00:00
[Original article ](https://clickhouse.tech/docs/en/sql-reference/aggregate-functions/reference/avg/ ) <!--hide-->