Skip to main content
GROUP BY clause
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 everything ROLLUP returns, plus subtotals for every other combination of the columns.
Last modified on October 16, 2026