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


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!


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

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 products_category_count AS (
FROM products_category_count;