GROUPING SETS, ROLLUP and CUBE extend GROUP BY so one query returns rows grouped at several levels. Columns that aren’t part of a row’s grouping come back as NULL.
GROUPING SETS
ROLLUP
Returns the grouped rows plus subtotal rows for each level, ending with a grand total.CUBE
Returns everythingROLLUP returns, plus subtotals for every other combination of the columns.