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

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

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

# select emp_no, (max(salary) - min(salary)) growth 
# from salaries
# where emp_no in (select if(to_date = '9999-01-01', emp_no, null) working from salaries)  # 获得在职员工id
# group by emp_no 
# order by growth asc 

# 获得涨幅
select t1.emp_no, (t2.end_salary - t1.start_salary) growth 
from 

(select e.emp_no emp_no, s.salary start_salary # 获得所有员工开始薪水
from employees as e, salaries as s 
where e.emp_no = s.emp_no and e.hire_date = from_date) as t1, 

(select emp_no, salary end_salary # 获得在职员工最新薪水
from salaries 
where to_date = '9999-01-01') as t2

where t1.emp_no = t2.emp_no 
order by growth asc 

注释掉的是默认只有涨薪没有降薪,用两个子查询获得开始和最新的薪水

全部评论

相关推荐

牛客37185681...:马德,我感觉这是我面过最恶心的公司,一面是两个女hr,说什么实习前几个月属于试用期,试用期过了才能转成正式实习生,我***笑了,问待遇就是不说,问能不能接受全栈,沙币公司
如果可以选,你最想去哪家...
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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