Skip to content
We areTOP 1%

Rank Scores

MediumLeetCodeSQL: Window Functions
Solve on LeetCode(opens in a new tab)
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews
Hint and exampleShow

Tied values must share a rank and the next rank must follow without a gap, which is exactly what DENSE_RANK does; quote an alias named rank in MySQL, where it is a reserved word.

Example: quiz(player, points)

player | points
A      | 50
B      | 80
C      | 80
D      | 60
SELECT player, points,
       DENSE_RANK() OVER (ORDER BY points DESC) AS position
FROM quiz;
-- B 80 1, C 80 1, D 60 2, A 50 3

More in SQL: Window Functions

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account