178. Rank Scores

Rank scores from highest to lowest. Equal scores share a rank, and the next rank follows with no gap. Return score and rank, highest first.

"No gap after a tie" is dense_rank. rank would skip numbers after ties.

Lesson: window functions.

Solutions

SELECT score, dense_rank() OVER (ORDER BY score DESC) AS rank
FROM Scores
ORDER BY score DESC;