H
handbtys
Guest
Hi, I'm a novice user of ACCESS and SQL.
I'm having trouble getting the following SQL to work the way I meant it to. I wanted to for each product, 1) SUM all the quantities ordered 2)SUM all the quantities manufactured, 3)Take the difference to find out my inventory holding.
This is the code that gives me weird results.
SELECT DISTINCTROW Products.ProductID, Sum(Manu_Details.UnitsCompleted) AS [Sum Of UnitsCompleted], Sum(Order_Details.Quantity) AS [Sum Of Quantity], [Sum Of UnitsCompleted]-[Sum Of Quantity] AS Inventory
FROM (Products INNER JOIN Manu_Details ON Products.ProductID = Manu_Details.ProductID) INNER JOIN Order_Details ON Products.ProductID = Order_Details.ProductID
GROUP BY Products.ProductID;
Apparently, if I had 3 orders for productid=2, totalling qty=10, The total quantity ordered will be given as 3 X 10. [Number of records multiplied by the correct number I want]
Can anybody point out what's wrong in the SQL i've written above which makes this happen?
Thanks.
I'm having trouble getting the following SQL to work the way I meant it to. I wanted to for each product, 1) SUM all the quantities ordered 2)SUM all the quantities manufactured, 3)Take the difference to find out my inventory holding.
This is the code that gives me weird results.
SELECT DISTINCTROW Products.ProductID, Sum(Manu_Details.UnitsCompleted) AS [Sum Of UnitsCompleted], Sum(Order_Details.Quantity) AS [Sum Of Quantity], [Sum Of UnitsCompleted]-[Sum Of Quantity] AS Inventory
FROM (Products INNER JOIN Manu_Details ON Products.ProductID = Manu_Details.ProductID) INNER JOIN Order_Details ON Products.ProductID = Order_Details.ProductID
GROUP BY Products.ProductID;
Apparently, if I had 3 orders for productid=2, totalling qty=10, The total quantity ordered will be given as 3 X 10. [Number of records multiplied by the correct number I want]
Can anybody point out what's wrong in the SQL i've written above which makes this happen?
Thanks.