Skip to content

average()

Calculate the time-weighted average of values in a TimeWeightSummary

Since 1.0.0

Calculate the time-weighted average. Equal to integral divided by the elapsed time. Note that there is a key difference to avg(): If there is exactly one value, avg() would return that value, but average() returns NULL.

Calculate the time-weighted average of the column val, using the ‘last observation carried forward’ interpolation method:

SELECT
id,
average(tws)
FROM (
SELECT
id,
time_weight('LOCF', ts, val) AS tws
FROM foo
GROUP BY id
) t

The syntax is:

average(
tws TimeWeightSummary
) RETURNS DOUBLE PRECISION
NameTypeDefaultRequiredDescription
twsTimeWeightSummary-The input TimeWeightSummary from a time_weight() call
ColumnTypeDescription
averageDOUBLE PRECISIONThe time-weighted average.