问题:对于数字列中的值,计算其累计差。例如:计算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;
问题:对于数字列中的值,计算其累计差。例如:计算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;