Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Basic multi-level aggregation
6. Multi-level aggregation – exercise
Multi-level aggregation in groups
Multi-level aggregation with custom classification
Three or more aggregation levels
Summary

Instruction

Good job! It's not that difficult, as you can see.

Whenever you write a report with multi-level aggregation, it's usually easiest to start by creating the inner query independently, and then turning it into a CTE by adding an outer query.

Now it's time to write your first multi-level aggregation report – without our assistance!

Exercise

What's the average number of products in each category? Show a single value in a column named AvgProductCount.

In the inner query, calculate the number of products for each category ID. In the outer query, find the average product count.

Stuck? Here's a hint!

Use the following template:

WITH ProductsCategoryCount AS (
  ...
)
SELECT
  ...
FROM ProductsCategoryCount;