3

谁能告诉我oracle 分区中suma的意义是什么sum (SUM(SUM(VAL))),在下面的代码片段中

SELECT NMS,
       SUM(SUM(VAL)) OVER(PARTITION BY NMS),  ---- SIGNIFICANCE
       EMPNO,
       SUM(SUM(VAL)) OVER(PARTITION BY EMPNO)   ---- SIGNIFICANCE
  FROM PART_TEST_PART
 GROUP BY NMS, EMPNO;
4

1 回答 1

6

VAL它计算每个NMS(对于第一个)和EMPNO(对于第二个)的总和。

首先评估 group by + SUM(VAL),然后分析计算该结果。

例如,如果您在 group by of 之后得到结果

EMPNO  NMS SUM(VAL)
1      a   15
1      b   24
2      a   50

SUM(SUM(VAL)) OVER(PARTITION BY NMS)会有

EMPNO  NMS SUM(VAL) SUM(SUM(VAL)) OVER(PARTITION BY NMS)
1      a   15       65  (15+50 for NMS = a)
1      b   24       24  (24 for NMS = b)
2      a   50       65  (15+50 for NMS = a)

SUM(SUM(VAL)) OVER(PARTITION BY EMPNO)会有

EMPNO  NMS SUM(VAL) SUM(SUM(VAL)) OVER(PARTITION BY EMPNO)
1      a   15       39  (15+24 for EMPNO = 1)
1      b   24       39  (15+24 for EMPNO = 1)
2      a   50       50  (50 for EMPNO = 2)
于 2013-01-03T12:45:58.513 回答