Part 58: Advanced Grouping: CUBE for Multi-Dimensional Cross-Tabulation
CUBE calculates all possible 2^N combinations of groupings for the specified dimensions.
1. Syntax
SELECT region, product_type, SUM(sales) AS revenue
FROM sales
GROUP BY CUBE (region, product_type);
Calculates:
1. (region, product_type)
2. (region)
3. (product_type)
4. () (Grand Total)
Key Takeaways
CUBEgenerates complete cross-tabulation matrices in a single execution.
In Part 59, we explore String Aggregation: STRING_AGG & GROUP_CONCAT!

