题目:查找员工编号emp_no为10001其自入职以来的薪水salary涨幅值growth

方法1:利用子查询查询最后一次工资和第一次工资
SELECT
(SELECT salary
FROM salaries
WHERE emp_no=10001
AND to_date=(SELECT MAX(to_date)
FROM salaries
WHERE emp_no=10001)
) -
(SELECT salary
FROM salaries
WHERE emp_no=10001
AND from_date=(SELECT MIN(from_date)
FROM salaries
WHERE emp_no=10001)
) AS growth;
注意:第二个子查询中的from_date可以改成to_date

方法1:利用ORDER BY查询最后一次工资和第一次工资
SELECT
(SELECT salary
FROM salaries
WHERE emp_no=10001
ORDER BY to_date desc limit 1
) -
(SELECT salary
FROM salaries
WHERE emp_no=10001
ORDER BY to_date asc limit 1
) AS growth;