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

Instruction

Okay! Now that we have a query that counts the number of items in each order, let's turn it into a CTE and calculate the average number of items for all orders.

Exercise

We've turned the query you wrote in the previous exercise into a CTE named order_items_counts. Now you need to complete the outer query, which should show a single column named avg_item_count that contains the average number of items in a single order.

Stuck? Here's a hint!

Outside the parentheses, add the following outer query:

SELECT
  AVG(item_count) AS avg_item_count 
FROM order_items_counts;