跳到主要内容

AVG

Aggregate function.

The AVG() function returns the average value of an expression.

Note: NULL values are not counted.

Syntax

AVG(expression)

Arguments

ArgumentsDescription
expressionAny numerical expression

Return Type

double

Examples

提示
numbers(N) – A table for test with the single `number` column (UInt64) that contains integers from 0 to N-1.
SELECT AVG(*) FROM numbers(3);
+--------+
| avg(*) |
+--------+
| 1 |
+--------+

SELECT AVG(number) FROM numbers(3);
+-------------+
| avg(number) |
+-------------+
| 1 |
+-------------+

SELECT AVG(number+1) FROM numbers(3);
+----------------------+
| avg(plus(number, 1)) |
+----------------------+
| 2 |
+----------------------+

SELECT AVG(number+1) AS a FROM numbers(3);
+------+
| a |
+------+
| 2 |
+------+