clause
CUBE
Generates all subsets of grouping columns. The number of grouping sets grows exponentially with the number of columns. 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 CUBE (column [, ...])Working Example
Example Snippetsql
SELECT customer_id, SUM(amount) FROM orders GROUP BY CUBE(customer_id) ORDER BY GROUPING(customer_id), customer_id;