sql21.查找所有员工自入职以来的薪水涨幅情况

查找所有员工自入职以来的薪水涨幅情况

http://www.nowcoder.com/questionTerminal/fc7344ece7294b9e98401826b94c6ea5

select a.emp_no, a.salary - b.salary as growth
from 
(select e.emp_no, s.salary 
from employees e join salaries s on e.emp_no = s.emp_no and s.to_date = '9999-01-01') 
as a, 
(select m.emp_no, n.salary 
 from employees m join salaries n on m.emp_no = n.emp_no and m.hire_date = n.from_date)
as b 
where a.emp_no = b.emp_no
order by growth;

我们现在要知道现在的工资,还要知道入职的工资,需要将salaries表分为两张表,
一张用来查询入职的工资,一张用来查询现在的工资,两者再用内连接联系起来

全部评论

相关推荐

你背过凌晨4点的八股文么:简历挂了的话会是流程终止,像我一样
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务