Is the following correct?
"SELECT

    Requires Free Membership to View

D.SEVK,(SUM(D.MIKTAR) - SUM(D.SEVK)) AS KALAN,S.CARI_KODU,S.TARIHI,D.STOK_KODU,D.SATISSIPARIS_NO,ST.ADI,D.MIKTAR,D.FIYATI, (D.MIKTAR*D.FIYATI) AS TUTAR,ST.BIRIM_KODU, D.INDIRIMORANI FROM KALE02.STOK ST, KALE02.SATISSIPARIS S, KALE02.SATISSIPARISDETAY D WHERE S.NO=D.SATISSIPARIS_NO AND D.STOK_KODU=ST.KODU GROUP BY D.STOK_KODU,D.SATISSIPARIS_NO"


No. Whenever you want to do an aggregate function like SUM(), this requires a GROUP BY, which you have, but the GROUP BY must include all columns mentioned in the SELECT list that are not involved in an aggregate function. Therefore, what you should try is

SELECT D.SEVK
     , (SUM(D.MIKTAR)-SUM(D.SEVK)) AS KALAN
     , S.CARI_KODU
     , S.TARIHI
     , D.STOK_KODU
     , D.SATISSIPARIS_NO
     , ST.ADI
     , D.MIKTAR
     , D.FIYATI
     , (D.MIKTAR*D.FIYATI) AS TUTAR
     , ST.BIRIM_KODU
     , D.INDIRIMORANI
  FROM KALE02.STOK ST
     , KALE02.SATISSIPARIS S
     , KALE02.SATISSIPARISDETAY D
 WHERE S.NO=D.SATISSIPARIS_NO
   AND      D.STOK_KODU=ST.KODU
 GROUP BY
       D.SEVK
     , S.CARI_KODU
     , S.TARIHI
     , D.STOK_KODU
     , D.SATISSIPARIS_NO
     , ST.ADI
     , D.MIKTAR
     , D.FIYATI
     , ST.BIRIM_KODU
     , D.INDIRIMORANI

Notice that (D.MIKTAR*D.FIYATI) AS TUTAR is not included in the GROUP BY because the individual columns are.

By the way, this may not give you the results you really want, but it is the correct way to code your GROUP BY.

For More Information


This was first published in May 2001

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.