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

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

http://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
group by d.dept_no
having s.salary = max(s.salary)
order by d.dept_no asc

这样只能得到每个部门的一个工资最大者,但其实可能有多个人的工资都是同一部门最大值

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

那就获得每个部门的最大工资,将工资表和部门表联合在一起,条件筛选每个人的工资是不是该部门下的最大工资。

全部评论

相关推荐

03-09 20:32
运营
牛客972656413号:成绩管理系统会不会有点太。。。
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务