spiderbaby
Programmer
Okay, I am trying to get this to work in subquery form because I seriously need to brush up on my subquery knowledge and for the life of me I cannot get it to work right. I can do innerjoins and get it to work but I know there is a way to do it other than innerjoins. I'm close but not close enough. Any help would be greatly appreciated.
SELECT (SELECT Cust_State
FROM Customers C
WHERE C.Cust_id = (SELECT Cust_id
FROM Orders O
WHERE O.Order_num = OT.Order_num)) AS State, Sales_total
FROM (SELECT Order_num, SUM(Quantity * Item_price) AS Sales_Total FROM Orderitems GROUP BY Order_num)OT
This gives me:
State Sales_Total
MI 1648
IN 329.6
AZ 1696
IL 189.6
MI 1867.5
My problem is that it's not summing up MI like it should. I've tried putting a group by in there and it doesn't work. Help please?
SELECT (SELECT Cust_State
FROM Customers C
WHERE C.Cust_id = (SELECT Cust_id
FROM Orders O
WHERE O.Order_num = OT.Order_num)) AS State, Sales_total
FROM (SELECT Order_num, SUM(Quantity * Item_price) AS Sales_Total FROM Orderitems GROUP BY Order_num)OT
This gives me:
State Sales_Total
MI 1648
IN 329.6
AZ 1696
IL 189.6
MI 1867.5
My problem is that it's not summing up MI like it should. I've tried putting a group by in there and it doesn't work. Help please?