clause

ROLLUP

Generates prefix grouping levels, including a grand total; column order determines the hierarchy. Example target: PostgreSQL 17. Use only the isolated starter dataset; setup and expected results are in the batch evidence.

Formal Syntax & Structure

sql syntaxsql
GROUP BY ROLLUP (column [, ...])

Working Example

Example Snippetsql
SELECT customer_id, SUM(amount) FROM orders GROUP BY ROLLUP(customer_id) ORDER BY GROUPING(customer_id), customer_id;
SQL Reference