题解 | #子查询解法#

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

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
一步到位,结构比较简单,但是嵌套了两层子查询,可能不是很好理解,但理清楚关系后还是挺简单的

全部评论

相关推荐

11-11 16:40
已编辑
门头沟学院 人工智能
不知道怎么取名字_:这个有点不合理了,相当于已经毕业了,但还是没转正,这不就是白嫖
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务