Relational Data - Aggregate Functions - Reference - Avg

From FojiSoft Docs
Revision as of 18:43, 28 August 2024 by Chris.Hansen (talk | contribs) (Import ClickHouse Docs: Wed Aug 28 2024 14:43:35 GMT-0400 (Eastern Daylight Time))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Calculates the arithmetic mean.

Syntax

avg(x)

Arguments

Returned value

  • The arithmetic mean, always as Float64.
  • NaN if the input parameter x is empty.

Example

Query:

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

Result:

┌─avg(x)─┐
│    2.5 │
└────────┘

Example

Create a temp table:

Query:

CREATE table test (t UInt8) ENGINE = Memory;

Get the arithmetic mean:

Query:

SELECT avg(t) FROM test;

Result:

┌─avg(x)─┐
│    nan │
└────────┘