-
Error in sqlcourse2.com lesson 9?
The exercise at the end of the lesson says "Select the item and per unit price for each item in the items_ordered table. Hint: Divide the price by the quantity."
The answer provided is:
select item, sum(price)/sum(quantity)
from items_ordered
group by item;
I think it should instead be:
select item, sum(quantity*price)/sum(quantity)
from items_ordered
group by item;
You can see why by looking at any item with a quantity exceeding 1, say, Sleeping Bags. Three Sleeping Bags were purchased, one at $89.22 and two at $88.70. This is a price per unit of ($89.22 + 2 x $88.70)/3 = $88.87. Compare this to the answer code provided, which generates a result of ($89.22 + $88.70)/3 = $59.31 for Sleeping Bags. It appears that the answer provided is ignoring the fact that two sleeping bags, not one, were purchased at a price of $88.70.
Have I understood this correctly?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|