Re: A Simple SQL Statement

From: Andrey Roslyakov <andrey-roslyakov_at_worldnet.att.net>
Date: 1997/10/27
Message-ID: <633lgc$54s_at_bgtnsc01.worldnet.att.net>#1/1


allsoft_at_hd1.vsnl.net.in wrote:
>
> 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
You can try this:
SELECT SD_ITEM,SUM(SD_QTY),SUM(b.PD_QTY)   FROM SALES_DETAILS,PURCHASE_DETAILS a,PURCHASE_DETAILS b   WHERE SD_ITEM = a.PD_ITEM (+) and a.PD_ITEM=b.PD_ITEM; Andre. Received on Mon Oct 27 1997 - 00:00:00 CET

Original text of this message