Documentation Index
Fetch the complete documentation index at: https://docs.oxla.com/llms.txt
Use this file to discover all available pages before exploring further.
Overview
TheAVG() window function calculates the average (arithmetic mean) of a set of numeric values within a window. This function allows you to compute averages over a set of rows that are related to the current row, such as rows within a partition of ordered set.
Syntax
The syntax for this function is as follows:Parameters
expression: column or expression that the function operates on (must be of numeric type)ROWS or RANGE: (optional) frame specification to control which rows are included in the calculation relative to the current row
Example
For the needs of this section, we will use a simplified version of thefilm table from the Pagila database, containing only the title, length and rating columns. The complete schema for the film table can be found on the
Pagila database website.
Rolling Average by Rating
The query below uses theAVG() function to calculate the rolling average of length as rows are ordered by rating: