Skip to main content
Since 1.3.0 Calculate a simple average (or mean) from the values in a statistical aggregate.
average(
  summary StatsSummary1D
) RETURNS DOUBLE PRECISION

Arguments

NameTypeDefaultRequiredDescription
summaryStatsSummary1D-The statistical aggregate produced by a stats_agg call

Returns

ColumnTypeDescription
averageDOUBLE PRECISIONThe average of the values in the statistical aggregate

Samples

Calculate the average of the integers from 0 to 100:
SELECT average(stats_agg(data))
  FROM generate_series(0, 100) data;
average
-----------
50