Overview
Give tied players the same place on a leaderboard, and know the difference between ROW_NUMBER(), RANK() and DENSE_RANK().
- ROW_NUMBER() 1, 2, 3
- RANK() 1, 1, 3
- DENSE_RANK() 1, 1, 2
Short Course
For tied scores, ROW_NUMBER() gives 1, 2, 3, RANK() gives 1, 1, 3 and
DENSE_RANK() gives 1, 1, 2. Trap: ROW_NUMBER() silently picks a winner
among equal scores, which is unfair on a leaderboard.
SELECT name, score,
DENSE_RANK() OVER (ORDER BY score DESC) AS level
FROM players; -- 100 → 1, 100 → 1, 90 → 2
Task
Return each player's name, score and place, where tied players share a
place and the next place is skipped (1, 1, 3), best first and ties by name.
In the database below, Bo and Cy share first place, so Ana is third.
Database
Sample data from the first test. The other tests use different rows, so write a query, not a list of answers.
| idINTEGER | nameTEXT | scoreINTEGER |
|---|---|---|
| 1 | Ana | 90 |
| 2 | Bo | 100 |
| 3 | Cy | 100 |
| 4 | Di | 70 |
Test Suites
Pending
Next
Output