Could someone help me to make a query that sets the value to field but only once per duplicated record? I do have some duplicated rows and I need a column that stores the value of my transaction only once. I did tried but without good effect, right now I'm stuck with a query like this.
SELECT JOURNALNUMBER, SUBLEDGERVOUCHER, ACCOUNTINGCURRENCYAMOUNT, MAINACCOUNTVALUE,
ITEMID, QTY, INVENTTRANSID,
(SELECT count(journalnumber)
FROM TestGeneralTransY AS tab
WHERE (TestGeneralTransY.JOURNALNUMBER = JOURNALNUMBER) AND (TestGeneralTransY.ITEMID = ITEMID)
AND (TestGeneralTransY.mainaccountvalue = mainaccountvalue) AND (TestGeneralTransY.ACCOUNTINGCURRENCYAMOUNT = ACCOUNTINGCURRENCYAMOUNT)
) AS MInAmount
FROM TestGeneralTransY
I want that the MinAmount would show only one valu per transaction like in PAF-004644308 I would need one row with value -79,5 and the second with 0. I do need this because I need to do sum calculations and with duplicated values its not possible for me.
JOURNALNUMBER | SUBLEDGERVOUCHER | ACCOUNTINGCURRENCYAMOUNT | MAINACCOUNTVALUE | ITEMID | QTY INVENTTRANSID | MInAmount |
---|---|---|---|---|---|---|
PAF-004644305 | WZ-0187132 | -39.750000 | 3110001 MPL-WST-0044 | -186.000000 PT020719031 1 | ||
PAF-004644308 | WZ-0187135 | -79.500000 | 3110001 MPL-WST-0036 | -260.000000 PT021519260 2 | ||
PAF-004644308 | WZ-0187135 | -79.500000 | 3110001 MPL-WST-0036 | -260.000000 PT021519260 2 | ||
PAF-004644324 | WZ-0187146 | -397.490000 3110001 MPA-PAL-0010 | -10.000000 | PT022252398 1 | ||
PAF-004647078 | WZ-0187322 | -10573.990000 | 3110001 MPL-FOR-0227 | -4500.000000 | PT022149061 1 | |
PAF-004654294 | FSL22000020 397.490000 | 3110001 MPA-PAL-0010 | -10.000000 | PT022252398 1 | ||
PAF-004654296 | FSL22000021 79.500000 | 3110001 MPL-WST-0036 | -260.000000 PT021519260 2 | |||
PAF-004654296 | FSL22000021 79.500000 | 3110001 MPL-WST-0036 | -260.000000 PT021519260 2 | |||
PAF-004654297 | FSL22000022 39.750000 | 3110001 MPL-WST-0044 | -186.000000 PT020719031 1 | |||
PAF-004660123 | FSL22000026 10573.990000 | 3110001 MPL-FOR-0227 | -4500.000000 | PT022149061 1 | ||
PAF-004667259 | WZ-0188549 | -357.740000 3110001 MPA-PAL-0010 | -9.000000 | PT022252398 1 | ||
PAF-004667260 | WZ-0188562 | -119.250000 3110001 MPL-WST-0044 | -260.000000 PT020719031 3 | |||
PAF-004667260 | WZ-0188562 | -119.250000 3110001 MPL-WST-0044 | -260.000000 PT020719031 3 | |||
PAF-004667260 | WZ-0188562 | -119.250000 3110001 MPL-WST-0044 | -260.000000 PT020719031 3 | |||
PAF-004673442 | WZ-0189010 | -73.770000 | 3110001 MPA-PAL-0010 | -1.000000 | PT022252398 1 | |
PAF-004673524 | WZ-0189011 | -39.750000 | 3110001 MPL-WST-0036 | -260.000000 PT021519260 1 | ||
PAF-004686484 | FSL22000103 39.750000 | 3110001 MPL-WST-0036 | -260.000000 PT021519260 1 | |||
PAF-004686612 | FSL22000104 431.510000 | 3110001 MPA-PAL-0010 | -9.000000 | PT022252398 2 | ||
PAF-004686612 | FSL22000104 431.510000 | 3110001 MPA-PAL-0010 | -1.000000 | PT022252398 2 | ||
PAF-004686824 | FSL22000106 119.250000 | 3110001 MPL-WST-0044 | -260.000000 PT020719031 3 | |||
PAF-004686824 | FSL22000106 119.250000 | 3110001 MPL-WST-0044 | -260.000000 PT020719031 3 | |||
PAF-004686824 | FSL22000106 119.250000 | 3110001 MPL-WST-0044 | -260.000000 PT020719031 3 |
1条答案
按热度按时间bnlyeluc1#
You can use
ROW_NUMBER()
to numerate your items, and thenCASE
to returnACCOUNTINGCURRENCYAMOUNT
only for first one.Please check if
OVER
clause ofROW_NUMBER()
makes sense for your data.