我有三个表(TABLE_A,TABLE_B,TABLE_C),我在C_MAIN_REF上加入它们。 TABLE_B有多个条目,我只需要返回一个,无关紧要?
任何想法?
编辑:
SELECT C.C_UNIT_CODE as BU,'EPLC' as PRODUCT, A.BENE_NM as CUSTOMER, A.C_MAIN_REF,
A.C_TRX_REF, A.PRES_CCY, TO_CHAR(A.PRES_AMT) AS PRES_AMT, A.PRES_DT AS PRES_DATE,
A.DOC_STAT, '' AS APPL_RESPONSE, A.SETTLE_STATUS as SETTLE_STATUS
FROM EPLC_EM_NEGO A
INNER JOIN CPYT_SCHEDULE B
ON a.C_MAIN_REF = b.C_MAIN_REF AND ROWNUM =1
INNER JOIN EPLC_MASTER C
ON a.C_MAIN_REF = c.C_MAIN_REF
WHERE a.CLS_DRWG_FLG = 'NO' AND b.CPYT_UNPAID_FLAG = 'T'
上面是我正在使用的当前查询,但问题是CPYT_SCHEDULE中有多个条目我不想这样,所以连接只包含CPYT_SCHEDULE表中的一行;
目前正在返回
BU PRODUCT CUSTOMER C_MAIN_REF C_TRX_REF PRES_CCY PRES_AMT PRES_DATE DOC_STAT SETTLE_STATUS
------------ ---------------------------------------------------- -------- --------- --------- ------------ -------------
GB01 EPLC Finance Customer No. 5 XL000053GB01 XL000053GB01-01 USD 90000 24-AUG-12 COMPLIANT Settle
GB01 EPLC Finance Customer No. 5 XL000053GB01 XL000053GB01-01 USD 90000 24-AUG-12 COMPLIANT Settle
GB01 EPLC Finance Customer No. 5 XL000053GB01 XL000053GB01-01 USD 90000 24-AUG-12 COMPLIANT Settle
GB01 EPLC Finance Customer No. 5 XL000053GB01 XL000053GB01-01 USD 90000 24-AUG-12 COMPLIANT Settle
但所需的输出是
BU PRODUCT CUSTOMER C_MAIN_REF C_TRX_REF PRES_CCY PRES_AMT PRES_DATE DOC_STAT SETTLE_STATUS
------------ ---------------------------------------------------- -------- --------- --------- ------------ -------------
GB01 EPLC Finance Customer No. 5 XL000053GB01 XL000053GB01-01 USD 90000 24-AUG-12 COMPLIANT Settle
答案 0 :(得分:3)
类似的东西:
SELECT C.C_UNIT_CODE as BU,
'EPLC' as PRODUCT,
A.BENE_NM as CUSTOMER,
A.C_MAIN_REF,
A.C_TRX_REF,
A.PRES_CCY,
TO_CHAR(A.PRES_AMT) AS PRES_AMT,
A.PRES_DT AS PRES_DATE,
A.DOC_STAT,
'' AS APPL_RESPONSE,
A.SETTLE_STATUS as SETTLE_STATUS
FROM EPLC_EM_NEGO A
INNER JOIN (select cs.*,
row_number() over (partition by C_MAIN_REF) as rn
from CPYT_SCHEDULE cs) b
ON a.C_MAIN_REF = b.C_MAIN_REF AND b.rn = 1
INNER JOIN EPLC_MASTER C
ON a.C_MAIN_REF = c.C_MAIN_REF
WHERE a.CLS_DRWG_FLG = 'NO'
AND b.CPYT_UNPAID_FLAG = 'T'
答案 1 :(得分:1)
以下子选项对我有用,感谢所有答案和输入。
SELECT C.C_UNIT_CODE as BU,'EPLC' as PRODUCT, A.BENE_NM as CUSTOMER, A.C_MAIN_REF, A.C_TRX_REF, A.PRES_CCY, TO_CHAR(A.PRES_AMT) AS PRES_AMT, A.PRES_DT AS PRES_DATE, A.DOC_STAT, '' AS APPL_RESPONSE, A.SETTLE_STATUS as SETTLE_STATUS
FROM E_EM_NEGO A, EPLC_MASTER C
WHERE a.CLS_DRWG_FLG = 'NO' AND a.C_MAIN_REF = c.C_MAIN_REF
AND a.C_MAIN_REF = (
SELECT C_MAIN_REF FROM CPYT_SCHEDULE B
WHERE B.CPYT_UNPAID_FLAG = 'T' AND b.C_MAIN_REF = a.C_MAIN_REF AND rownum=1)