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

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

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

select d.dept_no,d.emp_no,s.salary
from dept_emp d,salaries s
where (d.emp_no=s.emp_no) and (d.dept_no,s.salary) in
    (select d.dept_no,max(salary) 
     from salaries s,dept_emp d
     where s.emp_no=d.emp_no
     group by d.dept_no)
order by d.dept_no asc;

先找出每个部门的最高薪水和对应的部门ID

select d.dept_no,max(salary) 
     from salaries s,dept_emp d
     where s.emp_no=d.emp_no
     group by d.dept_no

查询的结果如下

再找出连接后的数据在子查询的表中的信息即可。

全部评论

相关推荐

刘湘_passion:太强了牛肉哥有被激励到
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务