73. Top Scorers With Ties
MediumRankingRANKTop-N with tiesRanking
To get a top-N that keeps ties, rank with RANK() and filter rank <= N. Because RANK gives tied rows the same rank (and skips the next), more than N rows can survive when the Nth place is tied — which is usually what 'top 3' means in a leaderboard.
The players table has a points total per player.
Task: return the top 3 ranks by points. If several players tie for a place, include all of them (so the result may have more than 3 rows).
Return columns player, points, rnk, ordered by rnk ascending, then player ascending.
Tables
Loading schema…
Expected outputrows must come back in this order
Computing expected output…
This is the result for the example data above. On Submit your query is graded against this example plus 4 hidden edge cases — 5test cases in all. A sloppy query that only fits the example won't pass.
SQL· SQLite · runs in your browser
⌘/Ctrl+↵ run · ⇧⌘/Ctrl+↵ submit
Run a query to see its output here.