Using GROUPING_ID to Distinguish Aggregation Levels in SELECT Statement
When working with ROLLUP or CUBE, you’ll notice NULL values appear in subtotals and grand totals.But how do you tell the difference between a real NULL value in the data and a NULL that just means “subtotal here”? That’s where GROUPING_ID comes in. It returns a numeric code indicating which columns are aggregated (rolled up). […]