2020-06-18 08:24:31 +00:00
---
2022-08-28 14:53:34 +00:00
slug: /en/sql-reference/aggregate-functions/reference/avg
2022-04-09 13:29:05 +00:00
sidebar_position: 5
2020-06-18 08:24:31 +00:00
---
2022-06-02 10:55:18 +00:00
# avg
2020-06-18 08:24:31 +00:00
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-09-19 20:05:54 +00:00
[Original article ](https://clickhouse.com/docs/en/sql-reference/aggregate-functions/reference/avg/ ) <!--hide-->