Window
MAX()
Overview
The MAX()
window function is used to compute the maximum value of an expression across a set of rows defined by a window specification.
Syntax
The syntax for this function is as follows:
Parameters
ALL
: retains all duplicate values from the expression
Example
For the needs of this section, we will use a simplified version of the film
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.
The query below uses the MAX()
to find the maximum length of films for each rating category and also calculate a running maximum length as you move through the films ordered by length. The RunningMaxLength
column will be updated as it encounters longer films.
By running the above code, we will get the following output: