题解 | #获取每个部门中当前员工薪水最高的相关信息#

获取每个部门中当前员工薪水最高的相关信息

http://www.nowcoder.com/practice/4a052e3e1df5435880d4353eb18a91c6

知识点

  1. 使用窗函数开窗,将两个表进行连接按部门进行分组排序,第一名为部门薪水最高员工
  2. 本题不可使用group by having进行编写原因还需再分析

代码

select t.dept_no, t.emp_no, t.salary maxSalary
from (
        select d.dept_no, d.emp_no, s.salary, rank()over(PARTITION by dept_no order by salary desc) srank
        from dept_emp d
        join salaries s
        on d.emp_no = s.emp_no
        and d.to_date = '9999-01-01'
        and s.to_date = '9999-01-01'
)t
where t.srank = 1
全部评论

相关推荐

评论
2
收藏
分享

创作者周榜

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