Skip to main content
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, players are ranked by their high score within each game level. Unlike RANK, DENSE_RANK assigns consecutive ranks with no gaps — players with equal scores share the same rank and the next rank is incremented by one.
SELECT
    nickname,
    level,
    highscore,
    DENSE_RANK() OVER (PARTITION BY level ORDER BY highscore DESC) AS game_rank
FROM
    (VALUES
        ('kennethpark', 9, 76),
        ('burchdenise', 9, 89),
        ('sabrina21', 9, 89),
        ('ymatthews', 9, 75)
    ) AS t(nickname, level, highscore)
ORDER BY level, nickname;
nickname textlevel inthighscore intgame_rank long
burchdenise9891
kennethpark9762
sabrina219891
ymatthews9753

Rows: 4Execution time: 2.03ms