题解 | #子查询解法#

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

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

全部评论

相关推荐

好消息是活的像个人了,周末可以约会吃饭打游戏了坏消息是钱没了,当初来小红书就是为了钱啊哭笑不得😭
犯困嫌疑人:好事儿啊,取消大小周能有更多自己的时间,周末还能约对象玩,这不美滋滋?
投递小红书等公司6个岗位 > 小红书取消大小周
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务