Click here to Skip to main content
15,886,794 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How can I modify the query below to show "average dollar value for Orders" and "average dollar value for OrderItems" side by side in columns. The query below would combine them. Thank you.
SQL
SELECT (COUNT(Orders.orderid) / SUM(Inventory.price)) AS Orders_Average
FROM  ORDERITEMS LEFT OUTER JOIN
               Inventory ON OrderItems.partid = Inventory.partid RIGHT OUTER JOIN
               Orders ON OrderItems.orderid = Orders.orderid
               
WHERE NOT EXISTS 
(SELECT *   
FROM  ORDERITEMS
WHERE OrderItems.orderid <> Orders.orderid
GROUP BY ORDERITEMS.orderid)
Posted
Updated 18-Jan-13 16:34pm
v2
Comments
Tharaka MTR 18-Jan-13 22:38pm    
Orders can have multiple order items. you are asking average value for orders, and average value for order items. could you please let us know how is your expecting output look likes
7prince 18-Jan-13 23:13pm    
yes that is correct. I am asking average value for orders, and average value for order items.

I would like to get the output in this format:

two columns: "Orders Average" and "OrderItems Average") or in one column with each output in its own row. Thank you.

1 solution

Hi
For average you need to do Sum over count and not count/sum.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900