avg

Calculates the arithmetic mean.

Syntax

  1. avg(x)

Arguments

  • x — Values.

x must be
Integer,
floating-point, or
Decimal.

Returned value

  • NaN if the supplied parameter is empty.
  • Mean otherwise.

Return type is always Float64.

Example

Query:

  1. SELECT avg(x) FROM values('x Int8', 0, 1, 2, 3, 4, 5)

Result:

  1. ┌─avg(x)─┐
  2. 2.5
  3. └────────┘

Example

Query:

  1. CREATE table test (t UInt8) ENGINE = Memory;
  2. SELECT avg(t) FROM test

Result:

  1. ┌─avg(x)─┐
  2. nan
  3. └────────┘