题解 | #获取员工其当前的薪水比其manager当前薪水还高的相关信息#

获取员工其当前的薪水比其manager当前薪水还高的相关信息

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

首先查询出员工表的信息:

select em.dept_no,em.emp_no,s.salary,em.to_date from dept_emp em join salaries s on em.emp_no=s.emp_no and em.to_date=s.to_date left join dept_manager ma on em.emp_no=ma.emp_no and em.dept_no=ma.dept_no where ma.dept_no is null

其次查询出经理人的信息: select em.dept_no,em.emp_no,s.salary,ma.to_date from dept_emp em join salaries s on em.emp_no=s.emp_no left join dept_manager ma on em.emp_no=ma.emp_no and em.dept_no=ma.dept_no where ma.dept_no is not null

最后两表连接在一起:(注意两表的连接条件除了to_date,还要部门号一致才具有可比性)

select a.emp_no,b.emp_no,a.salary,b.salary from

(select em.dept_no,em.emp_no,s.salary,em.to_date from dept_emp em join salaries s on em.emp_no=s.emp_no and em.to_date=s.to_date left join dept_manager ma on em.emp_no=ma.emp_no and em.dept_no=ma.dept_no where ma.dept_no is null ) a

join

(select em.dept_no,em.emp_no,s.salary,ma.to_date from dept_emp em join salaries s on em.emp_no=s.emp_no left join dept_manager ma on em.emp_no=ma.emp_no and em.dept_no=ma.dept_no where ma.dept_no is not null) b

on a.to_date=b.to_date where a.salary>b.salary and a.dept_no=b.dept_no

全部评论

相关推荐

程序员花海_:实习和校招简历正确格式应该是教育背景+实习+项目经历+个人评价 其中项目经历注意要体现业务 实习经历里面的业务更是要自圆其说 简历模板尽可能保持干净整洁 不要太花哨的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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