GROUP BY

    This statement is equivalent to:

    1. SELECT a, b, SUM( c ) FROM tab1 GROUP BY a, b
    2. UNION
    3. UNION
    4. SELECT null, b, SUM( c ) FROM tab1 GROUP BY b
    5. UNION
    6. SELECT null, null, SUM( c ) FROM tab1

    indicates whether a specified column expression in a GROUP BY list is aggregated or not. GROUPING returns 1 for aggregated or 0 for not aggregated in the result set.

    groupSet is a set of expression or column or it’s alias appearing in the query block’s SELECT list. groupSet ::= { ( expr [ , expr [ , ... ] ] )}

    expr is expression or column or it’s alias appearing in the query block’s SELECT list.

    1. SELECT a, b, SUM( c ) FROM tab1 GROUP BY GROUPING SETS ( (a, b), (a), (b), ( ) );
    2. SELECT a, b,c, SUM( d ) FROM tab1 GROUP BY ROLLUP(a,b,c)
    3. SELECT a, b,c, SUM( d ) FROM tab1 GROUP BY CUBE(a,b,c)

    ROLLUP(a,b,c) is equivalent to GROUPING SETS as follows:

    is equivalent to GROUPING SETS as follows:

    1. GROUPING SETS (
    2. ( a, b ),
    3. ( a, c ),
    4. ( a ),
    5. ( b, c ),
    6. ( b ),
    7. ( c ),
    8. )

    GROUP, GROUPING, GROUPING_ID, GROUPING_SETS, GROUPING SETS, CUBE, ROLLUP