AVG() OVER ...
All functions > WINDOW FUNCTION > AVG() OVER ...
Returns the average of values in the window frame.
Syntax
Diagram(
Sequence(
Terminal("AVG"),
Terminal("("),NonTerminal('expr'),Terminal(")"),
Terminal("OVER"),
Terminal("("),
NonTerminal("over_clause"),
Terminal(")"),
)
)| Parameter | Type | Required | Description |
|---|---|---|---|
expr | EXPRESSION | Yes | Numeric expression to average |
over_clause | OVER CLAUSE | Yes | OVER (PARTITION BY ... ORDER BY ... [FRAME ...]) |
Notes
- Calculates average over a window of rows
- PARTITION BY divides rows into independent groups
- ORDER BY determines row ordering within partitions
- Window frame controls which rows are included in the average
- Default frame is RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
- Useful for moving averages and rolling means
- Returns same type as input expression
- NULL values are ignored in the calculation