Used in conjunction with grouping-sets and super-groups, the GROUPING aggregate function returns a value that indicates whether or not a row returned in a GROUP BY answer set is a row generated by a grouping set that excludes the column represented by expression.
Example:
The following query:
SELECT SALES_DATE, SALES_PERSON, SUM(SALES) AS UNITS_SOLD, GROUPING(SALES_DATE) AS DATE_GROUP, GROUPING(SALES_PERSON) AS SALES_GROUP FROM SALES GROUP BY CUBE( SALES_DATE, SALES_PERSON) ORDER BY SALES_DATE, SALES_PERSON
Results in:
SALES_DATE SALES_PERSON UNITS_SOLD DATE_GROUP SALES_GROUP ---------- ------------ ---------- ---------- ----------- 12/31/1995 GOUNOT 1 0 0 12/31/1995 LEE 6 0 0 12/31/1995 LUCCHESSI 1 0 0 12/31/1995 - 8 0 1 03/29/1996 GOUNOT 11 0 0 03/29/1996 LEE 12 0 0 03/29/1996 LUCCHESSI 4 0 0 03/29/1996 - 27 0 1 03/30/1996 GOUNOT 21 0 0 03/30/1996 LEE 21 0 0 03/30/1996 LUCCHESSI 4 0 0 03/30/1996 - 46 0 1 ...................................