Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Single row wanted?

Status
Not open for further replies.

milton747

Programmer
Apr 21, 2005
133
US
I was hoping for 1 row for each itemcode. I'm getting many.
Goal was-> For all clients, all orders...how much did we sell of each item?

? Any help welcome.


SELECT customers.custID,
orders.orderID,
items.itemcode,
( items.pricequote * items.quantity ) As LineValue
FROM customers, orders, items
WHERE
customers.custID = orders.custID
AND orders.orderID = items.orderID
GROUP BY customers.custID,
orders.orderID,
items.itemcode,
items.pricequote,
items.quantity
ORDER BY 4 DESC, items.itemcode, customers.custID

 
Perhaps this ?
SELECT C.custID, o_OrderID, I.itemcode, Sum(I.pricequote * I.quantity) As LineValue
FROM (customers C
INNER JOIN orders O ON C.custID = O.custID)
INNER JOIN items I ON o_OrderID = I.orderID
GROUP BY C.custID, o_OrderID, I.itemcode
ORDER BY 4 DESC, 3, 1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top