【SQL】LeetCode-Rank Scores
阿新 • • 發佈:2021-02-06
技術標籤:SQL
LeetCode 178:Rank Scores
【Description】
Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ranking. Note that after a tie, the next ranking number should be the next consecutive integer value. In other words, there should be no “holes” between ranks.
For example, given the above Scores table, your query should generate the following report (order by highest score):
Important Note: For MySQL solutions, to escape reserved words used as column names, you can use an apostrophe before and after the keyword. For example
Rank
.
【Solution】
select Score, dense_rank() over (order by Score desc) as 'Rank' from Scores
dense_rank()
means that there are two people rank first, the third one still rank second.