GROUPING and GROUPING_ID Functions
These functions help identify which columns are part of subtotal rows in ROLLUP and CUBE.
Example:
SELECT department_id, job_id, SUM(salary),
GROUPING(department_id) AS dept_grp,
GROUPING(job_id) AS job_grp
FROM employees
GROUP BY ROLLUP(department_id, job_id);GROUPING returns 1 for NULLs created by ROLLUP/CUBE. GROUPING_ID combines them into a binary representation.