题解 | #查找在职员工自入职以来的薪水涨幅情况#

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

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

  1. 只使用salaries表
select distinct x.emp_no
,(select x1.salary from salaries x1 where x1.emp_no=x.emp_no and to_date='9999-01-01')
-(select x3.salary from salaries x3 where x3.emp_no=x.emp_no and 
  to_date=(select min(to_date) from salaries x2 where x2.emp_no=x.emp_no))
as growth 
from salaries x
where emp_no in (select distinct emp_no from salaries where to_date='9999-01-01')
order by growth
  1. 使用两个表,用from_date=hire_date判断入职salary
select distinct x.emp_no
,(select x1.salary from salaries x1 where x1.emp_no=x.emp_no and to_date='9999-01-01')-
(select x3.salary from salaries x3 where x3.emp_no=x.emp_no
 and x3.from_date=(select hire_date from employees e where e.emp_no=x.emp_no))
as growth
from salaries x
where emp_no in (select distinct emp_no from salaries where to_date='9999-01-01')
order by growth
全部评论

相关推荐

asdasdasdasdas:19岁,不容易啊可能升个本会好点,现在学历歧视太严重了
点赞 评论 收藏
分享
05-20 13:59
门头沟学院 Java
米黑子米黑子:你这个成绩不争取下保研?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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