题目要求查找员工编号emp_no为10001其自入职以来的薪水salary涨幅值growth。
首先通过子查询select salary from salaries where emp_no = 10001 order by to_date desc limit 0,1将当前的薪水找出来。
其次通过子查询select salary from salaries where emp_no = 10001 order by to_date limit 0,1将刚入职时薪水找出来。
最后两个相减,得到涨幅growth。
select (
(select salary from salaries where emp_no = 10001 order by to_date desc limit 0,1)
- (select salary from salaries where emp_no = 10001 order by to_date limit 0,1)
) as growth;