今天和大家聊的问题叫做 分数排名 ,我们先来看题面:https://leetcode-cn.com/problems/rank-scores/
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.
题意
编写一个 SQL 查询来实现分数排名。
解题
思路:排名问题直接可以用相关的窗口函数,由于Rank为关键字,所以必须加上反引号 。
SELECT score, dense_rank() over(ORDER BY score DESC) as `Rank` FROM scores;
好了,今天的文章就到这里,如果觉得有所收获,请顺手点个在看或者转发吧,你们的支持是我最大的动力 。