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

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

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

select

emp_no,

(now_salary - ago_salary) as growth

from

(select

emp_no,

sum(case when to_date = '9999-01-01' then salary else 0 end) as now_salary,

sum(case when from_date = hire_date then salary else 0 end) as ago_salary

from salaries natural join employees where emp_no in (

    select emp_no from salaries where to_date = '9999-01-01'

)

group by emp_no

) as tmp

order by growth

1.首先求在职员工当前的薪资,和入职时候的薪资

select

emp_no,

sum(case when to_date = '9999-01-01' then salary else 0 end) as now_salary, -- 当前薪资

sum(case when from_date = hire_date then salary else 0 end) as ago_salary -- 入职时薪资

from salaries natural join employees where emp_no in (

    select emp_no from salaries where to_date = '9999-01-01'

) -- 在职人员

group by emp_no -- 根据编号分组

2.然后在求出涨薪幅度,按照薪资涨幅升序

#担心入职之后被发现很菜怎么办#
全部评论

相关推荐

迷茫的大四🐶:你这个拿去投央国企吧,投私企包过不了的
点赞 评论 收藏
分享
牛客77743221...:做一段时间,公司出钱送你去缅甸和泰国旅游
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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