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

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

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

with a as(
    select emp_no from salaries where to_date = '9999-01-01' #找到符合要求的emp_no
),
b as(
    select s.emp_no ,salary, rank()over(partition by s.emp_no order by from_date ) r
    from salaries s, a
    where s.emp_no  = a.emp_no #排序
),
e as(
    select s.emp_no ,salary, rank()over(partition by s.emp_no order by from_date desc) r
    from salaries s, a
    where s.emp_no  = a.emp_no
),
c as(
    select emp_no, salary
    from b 
    where r = 1 #初始薪资
),
d as(
    select emp_no, salary
    from e
    where r = 1 #当前薪资
)
select c.emp_no, d.salary - c.salary growth
from c,d
where c.emp_no = d.emp_no
order by growth

全部评论

相关推荐

牛客49269852...:这家公司纯神人公司来的,约的我今早11点线下面试,我人都到了,10点和我说改线上,无敌
找实习记录
点赞 评论 收藏
分享
烤点老白薯:亲娘嘞🐶💩啊你的简历
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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