【发布时间】:2015-10-13 20:28:08
【问题描述】:
我有以下代码:
SELECT DISTINCT
tctc_cntipcli as "Type of contract" ,
texe_cncclipu as "Contract number",
TCTC_CNDOCIDC as "Client name",
tsrv_cndesser as "Service name",
texe_cnfuncid as "Service number",
tsrs_cnsubsdc as "Subservice name",
texe_cnsubser as "Subservice number",
tmap_cndesc as "Map",
(
SELECT to_char(count(tlof_cnlofrid))
from service.kndtlof
where
tlof_cncclipu = tctc_cncclipu and
tlof_cnservic = texe_cnfuncid and
tlof_cnsubser = texe_cnsubser and
tlof_cnfhalta > trunc (sysdate, 'mm')
) as "Volume of files messages" ,
(
select count(it.int_tran_id)
from internal_transactions it
join status ss on ss.int_tran_id = it.int_tran_id
join app_data ad on it.int_tran_id in
(
select distinct ad.int_tran_id
from app_data
where app_data.add_info_table in ('ACH', 'Wire')
)
join service.kndtexe ke on it.debit_acct in
(
select distinct texe_cnasupro
from service.kndtexe ke
where
(
(ke.texe_cnfuncid = '3001' and ke.texe_cnsubser = 'W1')
or
(ke.texe_cnfuncid = '3085' and ke.texe_cnsubser = 'I%')
)
)
where it.entry_timestamp > trunc(sysdate, 'mm')
) as "Volume of payments"
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 tctc_cncclipu in ('50008753')
order by tctc_cncclipu;
第二个子查询是从事务 db 查询到服务 db(请参阅业务需求图像),需要检查 texe 表中是否存在与 tctc 中的合同编号下的合同相关联的任何帐户,并且仅输出 3001 /W1 或 3085/I%。我如何过滤子查询来实现这一点?
【问题讨论】:
-
尝试格式化您的代码,以便人们阅读。显式
join有很大帮助。