AVG() OVER ...
All functions > WINDOW FUNCTION > AVG() OVER ...
Returns the average of values in the window frame.
Syntax
AVG(expr) OVER ([PARTITION BY expr [, ...]] [ORDER BY sort_item [, ...]] [ROWS|RANGE|GROUPS frame])
Notes
- Calculates average over a window of rows
- Useful for moving averages and rolling means
- Returns same type as input expression
- NULL values are ignored in the calculation
See also
Examples
FeatureQL
SELECT
f1 := ZIP(ARRAY[1,2,3] AS id, ARRAY[30,10,20] AS v).TRANSFORM(SELECT AVG(v) OVER (ORDER BY id ASC)).UNWRAP() -- Running average (v permuted so means differ from v)
;Result
| f1 ARRAY |
|---|
| [30.00, 20.00, 20.00] |