All problems

Ranking UrbanHop's Drivers

mediumSQLWindow Functions

Ops wants a full ranked leaderboard of drivers by rating, not just the top one, for an internal dashboard.

drivers

id name city rating
1 Sam Rios Austin 4.9
2 Priya Desai Denver 4.6
3 Oscar Lund Seattle 4.8
4 Nina Cole Austin 4.2

Task: Write a query that returns one row for every driver — all four, none dropped — with name, rating and rating_rank: their standing on the whole leaderboard, 1 being the best rated. Two drivers on the same rating share a number, and the number straight after it is skipped, so a board can read 1, 2, 2, 4. The dashboard prints the rows exactly as they arrive, so hand them back best rated first, two drivers sharing a number separated by name, alphabetically.

Example output — shape only, on an invented leaderboard of four other drivers, one of them showing the shared number and the skip that follows it.

name rating rating_rank
Vera Lindqvist 4.7 1
Ruth Abara 4.5 2
Tomas Aguilar 4.5 2
Kofi Mensah 4.1 4

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…