Instruction
Let's get started! Suppose we want to know the average total price paid (before discount) per order.
We know that we can use SUM(unit_price * quantity) to calculate the total price for a single order. However, we now need the average total price for all orders. In other words, we would like to use the AVG() function on values calculated by a call to SUM(unit_price * quantity). Unfortunately, SQL doesn't allow this type of construction: AVG(SUM(unit_price * quantity)).
What can we do? Let's find out!
Exercise
Run the template query. It answers the following question: What is the average total price paid (before discounts) per order? Take a look at the answer, and don't worry about the code – we'll analyze it in a second.
Stuck? Here's a hint!




