首页 > 其他 > 详细

10.2 查找同一组或分区中行之间的差

时间:2017-09-14 22:39:45      阅读:218      评论:0      收藏:0      [点我收藏+]

select deptno,ename,hiredate,sal,
coalesce(cast(sal-next_sal as char(10)),‘N/A‘) as diff
from (
select e.deptno,
e.ename,
e.hiredate,
e.sal,
(select min(sal) from emp d
where d.deptno=e.deptno
and d.hiredate =
(select min(hiredate) from emp d
where e.deptno=d.deptno
and d.hiredate > e.hiredate)) as next_sal
from emp e
) x 
order by 1;

10.2 查找同一组或分区中行之间的差

原文:http://www.cnblogs.com/liang545621/p/7523320.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!