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

select
    t2.emp_no,
    salary2-salary1 growth
from
    (
        (
            select
                s.emp_no,
                s.salary salary1,
                from_date
            from
                salaries s
                left join employees e on s.emp_no = e.emp_no
            where
                hire_date = from_date
        ) as t1
        left join (
            select
                s.emp_no,
                s.salary salary2,
                to_date
            from
                salaries s
                left join employees e on s.emp_no = e.emp_no
            where
                to_date = '9999-01-01'
        ) as t2 on t1.emp_no = t2.emp_no
    ) 
where
    t1.emp_no in (
        select
            s.emp_no
        from
            salaries s
            left join employees e on s.emp_no = e.emp_no
        where
            to_date = '9999-01-01'
    )
order by growth


全部评论

相关推荐

半导体德企 客户物流管理 10x14 硕士海归
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务