Introduction
CUBE
Summary

Instruction

Good job! Now, if we want to reduce the number of grouping combinations, we can exclude some columns from CUBE:

SELECT
  GROUPING_ID(Location, Gender, Risk) AS GroupingId,
  Location,
  Gender,
  Risk,
  MIN(Efficacy) AS MinEfficacy
FROM VaccineAdministration
GROUP BY 
  CUBE (Location, Gender), Risk;

In the query above, CUBE will create grouping combinations for Location and Gender, but Risk will be added to each grouping combination. As a result, we’ll get the following levels:

GROUP BY CUBE (Location, Gender), Risk =
GROUP BY Location, Gender, Risk +
GROUP BY Location, Risk +
GROUP BY Gender, Risk +
GROUP BY Risk

Exercise

Run the template query and note that Risk is now always used for grouping.