SQL Query Help
Hello,
I have a table Z_AUDIT_ALL_ENTRIES which has the following fields:
BUKRS CHAR 4 Company Code
BELNR CHAR 10 Accounting Document Number
GJAHR NUMC 4 Fiscal Year
BLART CHAR 2 Document type
BUDAT DATS 8 Posting Date in the Document
CPUDT DATS 8 Accounting Document Entry Date
BKTXT CHAR 25 Document Header Text
WAERS CUKY 5 Currency Key
HWAER CUKY 5 Local Currency
KURS2 DEC 9 Exchange Rate for the Second Local
KURSF DEC 9 Exchange rate
USNAM CHAR 12 User name
BUZEI NUMC 3 Number of Line Item Within Accounting
HKONT CHAR 10 General Ledger Account
PRCTR CHAR 10 Profit Center
KOSTL CHAR 10 Cost Center
DMBE2 CURR 13 Amount in Second Local Currency
DMBTR CURR 13 Amount in local currency
SHKZG CHAR 1 Debit/Credit Indicator
note field SHKZG has either "S" or "H" as a value.
I need to find all entries for BELNR where the (SUM(DMBTR) for "SHKZG = S") NOT EQUAL (SUM(DMBTR) for "SHKZG = H")
I do not know how to structure the query.I tried the following but ti did not work:
SELECT s.BELNR, s.SHKZG , SUM(s.DMBTR), h.BELNR, h.SHKZG , SUM(h.DMBTR)
FROM Z_AUDIT_ALL_ENTRIES s, Z_AUDIT_ALL_ENTRIES h
where
s.shkzg = 'S'
and
h.shkzg = 'H'
and
s.BUDAT = '20060101'
and
h.BUDAT = '20060101'
GROUP BY s.BELNR, h.belnr, s.SHKZG, h.SHKZG
having SUM(s.dmbtr) <> SUM(h.dmbtr)
order by s.BELNR asc, s.SHKZG, SUM(s.dmbtr) asc, h.belnr asc, h.SHKZG, SUM(h.dmbtr)
Any help is appreciated.
Message was edited by:
user554353