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;
转载于:https://www.cnblogs.com/liang545621/p/7523320.html
本文提供了一个复杂的SQL查询案例,用于从员工数据库中选择特定的数据。通过使用子查询和COALESCE函数,该查询能够找到每个部门内薪资差异,并按部门编号排序。

被折叠的 条评论
为什么被折叠?



