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

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

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

现在是2021.11
sql8.0
必须用到子查询才能通过,说明select在order by后面运行,其中rank在这个版本中作为关键字,不能作为别名,'rank'也不行,测试了下'xxx'也不行,说明别名不支持字符串?或者字符串不能作为列名?最后结果直接略过'xxx',仅对emp_no排名,会报错
select a.emp_no
, a.salary
, a.rk t_rank
from 
    (select emp_no
    , salary
    , dense_rank()over(order by salary desc)rk
    from salaries
    where to_date='9999-01-01')a
order by t_rank, emp_no
其他人的答案:
select emp_no, salary,
, dense_rank() over (order by salary desc) as rank
from salaries
where to_date='9999-01-01'
order by rank asc,emp_no asc;
现在已经不适用
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务