Q

Is the following correct?

Is the following correct? "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.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

Dig deeper on Oracle DBA jobs, training and certification

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close