IT lexicon › Database › CUBE (SQL)

CUBE (SQL)

Database På svenska → Updated: 2026-05-28

A SQL shortcut within GROUPING SETS that computes aggregations for ALL combinations of the given dimensions. GROUP BY CUBE (country, product) gives totals per (country+product), per country, per product, and overall — a complete cross-tabulation.

Logic: CUBE (a, b) produces (a,b), (a), (b), and () → 2^n groupings for n dimensions. The name comes from the OLAP "data cube": each dimension is an axis and CUBE materializes all aggregation planes. Distinct from ROLLUP (only the hierarchical roll-up, n+1 levels). Use CUBE when the dimensions are independent and you want to see every angle — "sales per region, per product, and every combination". Warning: 2^n grows fast → with many dimensions the result becomes enormous. A common basis for pivot tables and BI reports. A SQL standard. Together with ROLLUP and GROUPING SETS, SQL's tools for multidimensional aggregation without separate queries.

← Back to the lexicon