Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
GROUP BY – Recap
ROLLUP
Summary

Instruction

Excellent. Now, you may have noticed that when we wrote:

SELECT
  full_name,
  category, 
  AVG(score) AS avg_score
FROM contest_score
GROUP BY ROLLUP (full_name, category);

we got the following groupings:

  1. Average by full_name and category
  2. Average by full_name
  3. Overall average

In other words, we saw the full_name average, but we didn't see an average for category only. That's because the column order matters in ROLLUP. Let's check that out.

Exercise

Run the template query. Note that the order of columns inside the parentheses of ROLLUP has been reversed.

As you can see, we now have the following groupings:

  1. Average by full_name and category
  2. Average by category
  3. Overall average