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.
Samples
Section titled “Samples”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) tArguments
Section titled “Arguments”The syntax is:
average( tws TimeWeightSummary) RETURNS DOUBLE PRECISION| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| tws | TimeWeightSummary | - | ✔ | The input TimeWeightSummary from a time_weight() call |
Returns
Section titled “Returns”| Column | Type | Description |
|---|---|---|
| average | DOUBLE PRECISION | The time-weighted average. |