Hi all,
I'm trying to create what I thought was a simple inventory query, but I'm having a problem. I have a shipment table that looks like this:
SHIP_ID SHIP_QTY
1 24
2 12
Then a table that shows when certain items from a shipment are "processed" :
SHIP_ID PROCESSED_QTY
1 2
1 3
As you can see, a shipment can occur in the processed table multiple times, which leads to problems when I try to do the following query:
[code=oracle]
SELECT s.CLI_CODE as "Client", Sum(s.SHIP_QTY) - Sum(p.PROC_QTY) AS "No. of pallets on hand"
FROM SHIPMENT s, PROCESSED p
WHERE s.SHIP_ID = p.SHIP_ID
GROUP BY s.CLI_CODE;
[/code]
What happens is that the shipment quantity is added twice due to the duplicate entries in the processed table, resulting in 48-5, instead of 24-5 like I want. Anyone have any ideas? I need to keep the sum on the SHIP_QTY column due to multiple shipments from the same client. Thanks!
I'm trying to create what I thought was a simple inventory query, but I'm having a problem. I have a shipment table that looks like this:
SHIP_ID SHIP_QTY
1 24
2 12
Then a table that shows when certain items from a shipment are "processed" :
SHIP_ID PROCESSED_QTY
1 2
1 3
As you can see, a shipment can occur in the processed table multiple times, which leads to problems when I try to do the following query:
[code=oracle]
SELECT s.CLI_CODE as "Client", Sum(s.SHIP_QTY) - Sum(p.PROC_QTY) AS "No. of pallets on hand"
FROM SHIPMENT s, PROCESSED p
WHERE s.SHIP_ID = p.SHIP_ID
GROUP BY s.CLI_CODE;
[/code]
What happens is that the shipment quantity is added twice due to the duplicate entries in the processed table, resulting in 48-5, instead of 24-5 like I want. Anyone have any ideas? I need to keep the sum on the SHIP_QTY column due to multiple shipments from the same client. Thanks!
Comment