Skip to main content
Since 1.3.0 Calculate the average from a two-dimensional aggregate for the given dimension. For example, average_y() calculates the average for all the values of the y variable, independent of the values of the x variable.
average_y(
  summary StatsSummary 2D
) RETURNS DOUBLE PRECISION
average_x(
  summary StatsSummary 2D
) RETURNS DOUBLE PRECISION

Arguments

NameTypeDefaultRequiredDescription
summaryStatsSummary2D-The statistical aggregate produced by a stats_agg call

Returns

ColumnTypeDescription
average_y | average_xDOUBLE PRECISIONThe average of the values in the statistical aggregate

Samples

Calculate the average of the integers from 0 to 100:
SELECT average_x(stats_agg(y, x))
  FROM generate_series(1, 5) y,
       generate_series(0, 100) x;
average
-----------
50