Rank the current row within the requested window.

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

Syntax

DENSE_RANK() OVER ([PARTITION BY <partition_by>] ORDER BY <order_by> [ASC|DESC] )

Parameters

ParameterDescriptionSupported input types
<partition_by>The expression used for the PARTITION BY clause.Any
<order_by>The expression used in the ORDER BY clause. This parameter determines what value will be ranked.Any

Return Types

Same as input type

Example

In this example below, players are ranked based on their high scores for their game level.

SELECT
	nickname,
	level,
	highscore,
	DENSE_RANK() OVER (PARTITION BY level ORDER BY highscore DESC ) AS game_rank
FROM
	players;

Returns:

nicknamelevelhighscoregame_rank
kennethpark9766
sabrina2110783
rileyjon11941
ymatthews12924