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


Good! Now we'll show you how to write your own multi-level aggregation query. As we said earlier, we'll go step by step. Let's start with finding the average number of items in each order.

In step one, we'll count the items in each query.


Create a simple query (no CTE needed) that will show two columns: order_id and item_count. The item_count column should show the sum of quantities of all items in a given order.

Stuck? Here's a hint!

Use the order_items table. Group by order_id and use SUM(quantity).