average()

average(
    tws TimeWeightSummary
) RETURNS DOUBLE PRECISION

Compute a time-weighted average from a TimeWeightSummary.

This function is similar to integral but divides by the length of time being averaged.

Required arguments

NameTypeDescription
twsTimeWeightSummaryThe input TimeWeightSummary from a time_weight call

Returns

ColumnTypeDescription
averageDOUBLE PRECISIONThe time-weighted average computed from the TimeWeightSummary

Sample usage

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

Found an issue on this page?

Report an issue!

Keywords

Related Content