We use cookies for site analytics. Accept to help us understand how the site is used. See our Privacy Policy for details.
A medium sql problem, graded against 3 test cases (1 of them hidden).
Query-writing problems - joins, aggregation, window functions, and query tuning.
Reach for it when you see: A schema and a question about the data rather than a function signature.
More SQLproblems →```sql
SELECT id, score,
DENSE_RANK() OVER (ORDER BY score DESC) AS rank
FROM Scores
ORDER BY rank, id;
```
Three ranking functions side by side, scores [90, 90, 85, 70]:
| function | output |
|---|---|
| ROW_NUMBER() | 1, 2, 3, 4 |
| RANK() | 1, 1, 3, 4 |
| DENSE_RANK() | 1, 1, 2, 3 |
Pick based on what "rank" means in the spec: leaderboard typically wants `DENSE_RANK`, sports placings typically want `RANK`, anything that needs unique ordering wants `ROW_NUMBER`.
The full reference solution in every supported language stays in the editor above - reveal it there once you have had a real attempt.
Read off this problem's own test suite, so these are the cases a submission actually has to survive.
These apply to the pattern as a whole, not just this problem.