7.8 计算累计差

问题:对于数字列中的值,计算其累计差。例如:计算DEPTNO 10中工资的累计差。

select a.empno,a.ename,a.sal,
(select case when a.empno=min(b.empno) then sum(b.sal)
else sum(-b.sal)
end
from emp b 
where b.empno<=a.empno
and b.deptno=a.deptno) as rnk
from emp a
where a.deptno=10;

原文地址:https://www.cnblogs.com/liang545621/p/7523273.html