分析函式 - ROLLUP和GROUPING SETS

likesky276發表於2007-04-24

group by rollup(a,b,d)等同於group by grouping sets((a, b, d), (a,b), (a),( ) )

SQL> SELECT * FROM TEST2;

A B C D

---------- ---------- ------------ ----------

A B 1.00 E

A C 1.00 E

A D 2.00 F

A D 3.00 F

C D 3.00 F

C D 4.00 F

6 rows selected

SQL> select a,b,d,sum(c) from test2 group by rollup(a,b,d) order by a,b,d;

A B D SUM(C)

---------- ---------- ---------- ----------

A B E 1

A B 1

A C E 1

A C 1

A D F 5

A D 5

A 7

C D F 7

C D 7

C 7

14

11 rows selected

SQL> select a,b,d,sum(c) from test2 group by grouping sets((a, b, d), (a,b), (a),( ) ) order by a,b,d;

A B D SUM(C)

---------- ---------- ---------- ----------

A B E 1

A B 1

A C E 1

A C 1

A D F 5

A D 5

A 7

C D F 7

C D 7

C 7

14

11 rows selected


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8118583/viewspace-64865/,如需轉載,請註明出處,否則將追究法律責任。

相關文章