【SQL】LeetCode-Rank Scores

该博客介绍了如何使用SQL,特别是`dense_rank()`函数,来对分数进行排名。当分数相同时,它们会获得相同的排名,而下一个排名则无缝衔接,没有空缺。示例展示了在Scores表中根据分数降序排列并生成排名的查询方法。
摘要由CSDN通过智能技术生成

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值