题解 | #对所有员工的薪水按照salary降序进行1-N的排名#
对所有员工的薪水按照salary降序进行1-N的排名
http://www.nowcoder.com/practice/b9068bfe5df74276bd015b9729eec4bf
这里面个人认为两个点比较难: 1、s1.salary<=s2.salary -- 关联后还要统计:count(distinct s2.salary) 2、group by s1.emp_no,s1.salary -- 这里要分给两个列分组
select s1.emp_no,s1.salary,count(distinct s2.salary) rank --去重统计 from salaries s1 ,salaries s2 where s1.to_date = '9999-01-01' --当前时间 and s2.to_date = '9999-01-01' --当前时间 and s1.salary <= s2.salary --筛选条件 group by s1.emp_no,s1.salary order by s1.salary desc,s1.emp_no