题解 | #子查询解法#
查找在职员工自入职以来的薪水涨幅情况
http://www.nowcoder.com/practice/fc7344ece7294b9e98401826b94c6ea5
select a.emp_no, (select salary from salaries s where a.emp_no=s.emp_no and s.to_date=(select max(to_date) from salaries t where s.emp_no=t.emp_no group by t.emp_no)) -(select salary from salaries s where a.emp_no=s.emp_no and s.from_date=(select min(from_date) from salaries t where s.emp_no=t.emp_no group by t.emp_no)) as growth from salaries a where a.to_date = '9999-01-01' order by growth asc一步到位,结构比较简单,但是嵌套了两层子查询,可能不是很好理解,但理清楚关系后还是挺简单的