Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
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 avg_age
FROM vaccine_administration
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.