LeetCode:分数排名

https://leetcode-cn.com/problems/rank-scores/

Rank比较难想出来,这里的思路是对于任意分数X,X的排名Rank等价于其他分数中大于等于X分数的(去重)个数,例如X=100分,属于最高分,那么大于等于X的分数个数就为1,也就是排名为1。

select s1.Score, count(distinct s2.Score) Rank
from scores s1, scores s2
where s1.Score<=s2.Score
group by s1.id
order by s1.Score desc;
发布了360 篇原创文章 · 获赞 73 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/weixin_43777983/article/details/105545156