An extension of GROUP BY that generates subtotal and grand-total rows automatically. Produces a result set with multiple levels of aggregation in a single query.
Generates hierarchical subtotals from the specified columns, from the most granular to a grand total. GROUP BY ROLLUP(a, b) produces groupings for (a, b), (a), and (). Useful for analytical reports with drill-down totals.
| Database System | Support Status | Since Version | Notes |
|---|---|---|---|
| MySQL | ✓ Supported | 4.1 | MySQL uses the non-standard WITH ROLLUP modifier on GROUP BY, available since 4.1. MySQL 8.0 also accepts the standard GROUP BY ROLLUP(...) syntax. Use GROUPING(col) (added in 8.0) to distinguish NULL subtotal rows from actual NULL data values. HAVING filtering applies after rollup rows are generated. |
| PostgreSQL | ✓ Supported | 9.5 | Standard GROUP BY ROLLUP(...) syntax. GROUPING(col) function available to identify rollup-generated NULL rows. Can be combined with GROUPING SETS and CUBE in the same GROUP BY clause. |
| SQL Server | ✓ Supported | 2008 | Standard GROUP BY ROLLUP(...) syntax supported since 2008. The older WITH ROLLUP modifier (SQL Server 2005 syntax) is also still accepted. GROUPING(col) and GROUPING_ID(...) available to detect rollup rows. |
| Oracle | ✓ Supported | 8i | Standard GROUP BY ROLLUP(...) syntax, available since Oracle 8i. GROUPING(col) and GROUPING_ID() available. Can combine ROLLUP, CUBE, and GROUPING SETS in one GROUP BY clause. |
| SQLite | ✗ Not Supported | — | ROLLUP is not supported. Workaround: use UNION ALL to manually combine the detailed rows, subtotals, and grand total. |
ROLLUP(a, b, c) generates n+1 grouping levels: (a,b,c), (a,b), (a), and (). The NULL values in subtotal rows represent 'all values for this column' — use GROUPING(col) to distinguish them from genuine NULL data. MySQL is the only engine that uses a non-standard WITH ROLLUP modifier syntax as its primary form (though it also accepts standard syntax in 8.0+). SQLite is the only major engine with no ROLLUP support at all.
MySQL uses the non-standard WITH ROLLUP modifier on GROUP BY, available since 4.1. MySQL 8.0 also accepts the standard GROUP BY ROLLUP(...) syntax. Use GROUPING(col) (added in 8.0) to distinguish NULL subtotal rows from actual NULL data values. HAVING filtering applies after rollup rows are generated.
Standard GROUP BY ROLLUP(...) syntax. GROUPING(col) function available to identify rollup-generated NULL rows. Can be combined with GROUPING SETS and CUBE in the same GROUP BY clause.
Standard GROUP BY ROLLUP(...) syntax supported since 2008. The older WITH ROLLUP modifier (SQL Server 2005 syntax) is also still accepted. GROUPING(col) and GROUPING_ID(...) available to detect rollup rows.
Standard GROUP BY ROLLUP(...) syntax, available since Oracle 8i. GROUPING(col) and GROUPING_ID() available. Can combine ROLLUP, CUBE, and GROUPING SETS in one GROUP BY clause.
ROLLUP is not supported. Workaround: use UNION ALL to manually combine the detailed rows, subtotals, and grand total.