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

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

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

分别胜场当前的薪水表和入职的薪水表,注意因为只要当前的员工不包含已经离职的员工,所以两表应用INNER JOIN

SELECT s_to.emp_no,(s_to.salary - s_from.salary) AS growth
FROM
(SELECT e.emp_no,s.salary
FROM employees as e
INNER JOIN salaries as s
on e.emp_no = s.emp_no and s.to_date = '9999-01-01') AS s_to
INNER JOIN
(SELECT e.emp_no,s.salary
FROM employees as e
INNER JOIN salaries as s
ON e.emp_no = s.emp_no and s.from_date = e.hire_date) AS s_from
ON s_to.emp_no = s_from.emp_no
ORDER BY growth
全部评论

相关推荐

评论
点赞
收藏
分享
牛客网
牛客企业服务