Instruction
Okay! Let's do two similar exercises to practice the pattern.
Exercise
For each shipping country, we want to find the average count of unique products in each order. Show the ship_country and avg_distinct_item_count columns. Sort the results by count, in descending order.
In the inner query, find the number of distinct products in each order and select it alongside the ship_country column. In the outer query, apply the proper aggregation.
Stuck? Here's a hint!
Use the following template:
WITH order_distinct_items AS ( ... ) SELECT ... FROM order_distinct_items GROUP BY ... ORDER BY ... DESC;




