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

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

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

1、题目要求:

(1)计算出每位在职员工从入职到现在的薪水涨幅;

(2)结果按照growth升序排序;

2、解题:

(1)获取员工入职时的薪资——表连接查询,根据员工id和入职日期获取员工入职时的薪资;

(2)获取在职员工当前的薪资——表连接查询,根据员工id和‘to_date’获取在职员工的当前薪资;

(3)计算二者差值,升序排序。

select nt.emp_no emp_no,nt.salary - bt.salary growth
from (select em.emp_no emp_no,sa.salary salary
from employees em
inner join salaries sa
on em.emp_no = sa.emp_no and em.hire_date = from_date) bt
inner join (
    select em.emp_no emp_no,sa.salary salary
from employees em
inner join salaries sa
on em.emp_no = sa.emp_no
where to_date = '9999-01-01'
) nt
on bt.emp_no = nt.emp_no
order by growth

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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