Returns the maximum value within the requested window.

For more information on usage, please refer to Window Functions.

Syntax

MAX( <expression> ) OVER ( [ PARTITION BY <partition_by> ] )

Parameters

ParameterDescriptionSupported input types
<expression>A value used for the MAX functionAny
<partition_by>An expression used for the PARTITION BY clause.Any

Return Types

Same as input type

Example

The example below queries test scores for players in various grade levels. Unlike a regular MAX() aggregation, the window function highlights how each player individually compares to the highest game score for their level.

SELECT
	nickname,
	level,
	current_score,
	MAX(current_score) OVER (PARTITION BY level) AS highest_score
FROM
	players;

Returns:

nicknamelevelcurrent_scorehighest_score
kennethpark97695
sabrina2179098
burchdenise57999
ymatthews68593
rileyjon88084