题解 | #对所有员工的薪水按照salary降序进行1-N的排名#

对所有员工的薪水按照salary降序进行1-N的排名

http://www.nowcoder.com/practice/b9068bfe5df74276bd015b9729eec4bf

用dense_rank排名,可以处理并列情况并且不会跳排名

select emp_no, salary, 
dense_rank() over (order by salary desc) as ranking
from salaries

通过计算有多少salary不小于当前salary来计算排名

select s1.emp_no, s1.salary, 
(select count(distinct salary) 
 from salaries 
 where salary >= s1.salary) as ranking
 from salaries as s1
 order by s1.salary desc, s1.emp_no
全部评论

相关推荐

回家当保安:复旦✌🏻,佬你的简历感觉挺好的,寒假日常hc比较少。佬可以过完年之后再试试,日常实习hc比较充足
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务