我有以下选择。它会调用单独的DB来收集所需的所有信息。除了最后一个选择值(VolumeOfPayments)之外,一切看起来都很好,即使前面的其他输出不同(SubserviceName / SubserviceNumber / Map),它也会重复值。如何根据上述字段选择不同的选项? 选择如下:
SELECT DISTINCT
tctc_cntipcli as "TypeOfContract" ,
texe_cncclipu as "ContractNumber",
tctc_cndocidc as "ClientName",
tsrv_cndesser as "ServiceName",
texe_cnfuncid as "ServiceNumber",
tsrs_cnsubsdc as "SubserviceName",
texe_cnsubser as "SubserviceNumber",
tmap_cndesc as "Map",
(
SELECT DECODE(to_char(count(tlof_cnlofrid)), '0', 'NA', COUNT(TLOF_CNLOFRID))
from service.kndtlof
where tlof_cncclipu = texe_cncclipu
and tlof_cnservic = texe_cnfuncid
and tlof_cnsubser = texe_cnsubser
and tlof_cnfhalta > trunc (sysdate, 'mm')
) as "VolumeOfFilesMessages",
(select DECODE(to_char(count(it.int_tran_id)), '0','NA', COUNT(IT.INT_TRAN_ID))
from internal_transactions it, status ss, app_data ad -- TRANSACTIONS DB CALL, WHICH HOLDS TRANSACTION INFO FOR CONTRACTS IN THE SERVICS DB
where it.debit_acct IN (select distinct ke.texe_cnasupro
from service.kndtexe ke -- CALL TO SERVICES DB WHICH HOLDS CONTRACT LEVEL INFO, OR THE SELECT VALUES ABOVE
where (
(texe_cnfuncid = '3001' and texe_cnsubser = 'W1')
or
(texe_cnfuncid = '3085' and texe_cnsubser LIKE ('I%'))
)
--and texe_cncclipu = tctc_cncclipu
--and texe_cnfuncid = tsrv_cncveser
--and texe_cnfuncid = tsrs_cncveser
--and texe_cnsubser = tsrs_cnsubser
--and texe_cncclipu = tscm_cncontra
--and texe_cnfuncid = tscm_cnservic
--and texe_cnsubser = tscm_cnsubser
--and tscm_cnmapco = tmap_cnmapco
--and tscm_cnservic = tmap_cnservic
)
and it.entry_timestamp > trunc (sysdate, 'mm')
and it.int_tran_id = ss.int_tran_id
and ss.stage in ('ACHPayment_Confirmed', 'HIFV5_FTRINF', 'Payment_HIFV5_FTRINF', 'HIFV4')
and it.int_tran_id = ad.int_tran_id
and (
(ad.add_info_table ='Wire' /*and KE.texe_cnfuncid = '3001' AND TEXE_CNSUBSER = 'W1'*/)
or
(ad.add_info_table = 'ACH' and texe_cnfuncid = '3085' AND TEXE_CNSUBSER LIKE ('I%'))
)
) as "VolumeOfPayments"
from service.kndtctc, service.kndtexe, service.kndtscm, service.kndtsrv, service.kndtsrs, service.kndtmap
where tctc_cncclipu = texe_cncclipu
and texe_cnfuncid = tsrv_cncveser
and texe_cnfuncid = tsrs_cncveser
and texe_cnsubser = tsrs_cnsubser
and texe_cncclipu = tscm_cncontra
and tscm_cnmapco = tmap_cnmapco
and tscm_cnservic = tsrv_cncveser
and tscm_cnsubser = tsrs_cnsubser
and tctc_cnestado in ('01', '03')
and texe_cnestado in ('01', '03')
and tsrv_cnestado in ('01', '03')
and tsrs_cnestado in ('01', '03')
and tscm_cnestado in ('01', '03')
and tmap_cnestado in ('01', '03')
AND TEXE_CNCCLIPU = '50009823'
AND TEXE_CNFUNCID = '3085'
order by texe_cncclipu
;
感谢您的时间......