The answer is: $2,183.90select sum([on hand] * [cost]) as [total cost] from item
2. Calculate the total profit if you sold all the items on-hand.
(Again the number of each item is also to be taken into account.)
(Do it, or think about it, in two stages.) select sum( [on hand] * ([selling
price] - [cost]) )
from item
The answer is: $664.92.
3. Calculate the average cost of the items on-hand.
(Definition) One calculates the average cost by
What matters is the number of types of items and their individual costs.
The answer is: $15.31 select avg(cost)
from item
4. Display the items that cost below average.
(Take the average to be the one calculated in the previous query).
We've done this kind of exercises on Thu before the exam. select [item id], description, cost
from item
where cost <= (select avg(cost) from item);
The answer is:
(One can easily verify this query by hand).
item id description cost 3663 Baseball Cap $9.25 3683 Coffee Mug $1.85 4563 Glasses (4) $8.20 5953 Knit Cap $4.95 6189 Sports Towel $3.58 7930 Tee Shirt $8.90
5.Calculate the total cost of the "Beverage Holders" items you have on-hand.
(The number of items of each kind you have on hand is to be taken into account).
Start from this:
The answer eventually is:
select [item id], description, cost
from
item, vendor
where vendor.[vendor code] = item.[vendor code] and vendor.name = "Beverage Holders"
Here's another version:SELECT sum(cost) AS [total cost] FROM item, vendor WHERE vendor.[vendor code]=[item].[vendor code] AND vendor.name="Beverage Holders";
6. What's the profit if you sell all "Beverage Holders" items you have?select sum(cost), vendor.name from vendor, item where vendor.[vendor code] = item.[vendor code] group by vendor.name having vendor.name="Beverage Holders"
Definition: It is the
This produces the following answer:select sum([on hand] * ([selling price] - [cost])) as profit, vendor.name from vendor, item where vendor.[vendor code] = item.[vendor code] group by vendor.name
7. Calculate the average item cost per vendor (three averages, for the three vendors).
profit name $282.15 Arnie Cheer $73.40 Beverage Holders $309.37 Logo Greats
(The number of items of each kind currently in the store is not relevant, just as in query 3.)
Too easy, by now.
This gives:
select avg(cost) as [average cost], vendor.name
from vendor, item
where vendor.[vendor code] = item.[vendor code]
group by vendor.name
average cost name $18.03 Arnie Cheer $5.03 Beverage Holders $17.74 Logo Greats