A Simple SQL Query
Posted in 1997
Topics: SQL Development & Query Writing
Can someone help me solve this simple problem ? There are two tables, and
I need a summary of the items. For SUM(SD_QTY) I get the right figure,
but for SUM(PD_QTY) I get the figure multiplied by 3.
------------------- Table : PURCHASE_DETAILS
----------------------------
PD_ITEM PD_QTY
3 2
------------------- Table : SALES_DETAILS
----------------------------
SD_ITEM SD_QTY
3 100
3 1
3 3
4 200
SB 1
---------------------- S Q L
--------------------------------------------------------------
SELECT SD_ITEM, SUM(SD_QTY), SUM(PD_QTY)
FROM SALES_DETAILS, PURCHASE_DETAILS
WHERE SD_ITEM = PD_ITEM (+)
GROUP BY SD_ITEM;----------------------- Result
--------------------------------------------------------
SD_ITEM Sum(SD_QTY) Sum(PD_QTY)
3 104 6 <-------- This should
be 2
4 200
SB 1
----------------------- Thank you in advance
--------------------------------------
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet