Introduction
CUBE
Summary

Instruction

Let’s get started. In principle, ROLLUP and CUBE are similar. The difference is that CUBE does not remove columns from the right to create grouping levels. Instead, it creates every possible grouping combination based on the columns inside its parentheses. Take a look:

SELECT
  Location, 
  Gender, 
  Risk, 
  AVG(Age) AS AvgAge
FROM VaccineAdministration
GROUP BY 
  CUBE (Location, Gender, Risk);

Syntax-wise, we only replaced ROLLUP with CUBE. Let’s see what result we’ll get.

Exercise

Run the template query and note how many grouping levels are created.