分析函数计算基于组的某种聚合值

  select ename, deptno, sal,
       sum(sal) over
         (order by deptno, ename) running_total,
       sum(sal) over
         (partition by deptno
          order by ename) department_total,
       row_number() over
         (partition by deptno
          order by ename) seq
   from scott.emp
   order by deptno, ename

ENAME          DEPTNO        SAL RUNNING_TOTAL DEPARTMENT_TOTAL        SEQ
---------- ---------- ---------- ------------- ---------------- ----------
CLARK              10       2450          2450             2450          1
KING                        5000          7450             7450          2
MILLER                      1300          8750             8750          3
    
ADAMS              20       1100          9850             1100          1
FORD                        3000         12850             4100          2
JONES                       2975         15825             7075          3
SCOTT                       3000         18825            10075          4
SMITH                        800         19625            10875          5
    
ALLEN              30       1600         21225             1600          1
BLAKE                       2850         24075             4450          2
JAMES                        950         25025             5400          3
MARTIN                      1250         26275             6650          4
TURNER                      1500         27775             8150          5
WARD                        1250         29025             9400          6
    
14 rows selected.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值