Instruction
Just like ROLLUP, CUBE can also be used with GROUPING_ID() to get numerical IDs for each grouping level:
SELECT GROUPING_ID(Location, Gender, Risk) AS GroupingId, Location, Gender, Risk, AVG(Efficacy) AS AvgEfficacy FROM VaccineAdministration GROUP BY CUBE (Location, Gender, Risk);
Let’s see what happens.
Exercise
Run the template query and note how many GROUPING_ID() values are created.



