题解 | #对所有员工的薪水按照salary降序排名#

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

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

SELECT emp_no, salary, (select count(distinct s2.salary) from salaries s2 where s2.salary >= s1.salary) AS rank_num
FROM salaries s1
ORDER BY salary DESC, emp_no ASC;

手搓rnkk函数

(select count(distinct s2.salary) from salaries s2 where s2.salary >= s1.salary)

这个子查询是精髓,查出了s1.emp_no对应的工资的排名,并且用distinct防止重复计数

全部评论

相关推荐

吃就完事了:别找单做硬件的找做电源的,电源工程师
点赞 评论 收藏
分享
09-28 17:38
门头沟学院 Java
小肥罗:众生皆吗喽,那满山吗喽也是我腚最红!!!
我的秋招日记
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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