日期:2014-05-17 浏览次数:20827 次
CREATE TABLE T(A INT, B INT, C VARCHAR2(4)); INSERT INTO T VALUES (1, 10, 'A'); INSERT INTO T VALUES (1, 10, 'B'); INSERT INTO T VALUES (1, 10, 'C'); INSERT INTO T VALUES (2, 5, 'A'); INSERT INTO T VALUES (2, 5, 'B'); SELECT DECODE(GROUPING(A), 1, NULL, B) A, DECODE(GROUPING(B), 1, SUM(B), B) B, C FROM T GROUP BY ROLLUP(A, (B, C)) HAVING GROUPING_id(a,B)<>3 ; 返回: 10 10 A 10 10 B 10 10 C 30 5 5 A 5 5 B 10