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

WITH a AS (
    SELECT emp_no, salary
    FROM salaries 
    WHERE to_date = '9999-01-01'
),
b AS (
    SELECT s.emp_no, s.salary
    FROM salaries s
    JOIN employees e ON s.emp_no = e.emp_no
    WHERE s.from_date = e.hire_date
)
SELECT a.emp_no, a.salary - b.salary AS growth 
FROM a 
INNER JOIN b 
ON a.emp_no = b.emp_no
order by growth;

生成两张表,根据两张表的结果做。

全部评论

相关推荐

字节 测开 25*15
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务