- 预先
WITH pims AS
(
SELECT code, value
FROM T_QNT_EXT_INFO_TITRES
WHERE filter = 'PIMS'
AND key = 'INSTRUMENT'
),
generic_param_value as
(
select value
from T_OPS_GENERIC_PARAM
where process='PIMSREC'
and field in('HBEU_ISSU_INC','HBEU_INV_INC',
'HBEU_TRADE_INC', 'HBAP_TRADE_INC')
)
select t.sicovam, pims.value ,t.devisectt
from titres t,
AUDIT_MVT a,
histomvts h,
pims
WHERE t.sicovam = pims.code
and pims.value is not null
and t.affectation not in (4, 12)
and t.type not in ('A','F','E','M')
and t.sicovam IN (SELECT DISTINCT nvl(h.sicovam, a.sicovam)
FROM AUDIT_MVT a, histomvts h
WHERE a.refcon=h.refcon(+)
AND a.DATEMODIF >= (SELECT MAX(MARKER_DATE)
FROM REMOTE_SECURITY.MARKERS
WHERE MARKER LIKE '%_SOPUS.%'
AND MARKER_DATE < TO_DATE('&2 10:00','YYYYMMDD HH:MI'))
AND a.DATEMODIF < (SELECT NVL(MIN(MARKER_DATE),SYSDATE) FROM REMOTE_SECURITY.MARKERS WHERE MARKER LIKE '%_SOPUS.%' AND MARKER_DATE > TO_DATE('&2 10:00','YYYYMMDD HH24:MI'))
AND EXISTS (select 1 from business_events b where decode(a.version,1,h.type,a.type)=b.id and (b.compta in (0,1) or b.id=15))
AND coalesce(a.hsbc_opcvm_upd, 0) <> 1 --mark a trade's modification if it's Drag and Drop
AND decode(a.version,1,h.typesico,a.typesico) NOT IN (4)
AND exists (SELECT 1 FROM FOLIO, generic_param_value where ident=decode(a.state, 3, a.opcvm, h.opcvm) START WITH IDENT =generic_param_value.value
CONNECT BY PRIOR IDENT = MGR)
)
and not exists (SELECT 1 FROM T_QNT_EXT_INFO_TITRES t2 WHERE t2.CODE = t.sicovam
and t2.filter = 'PIMS'
and t2.KEY = 'TYPE'
and t2.VALUE in ('DPT', 'DFD/LBK')
)
and (((pims.value like 'P%')
and
((t.affectation <>5)
OR
(t.affectation=5 and (exists(select 1 from histomvts where contrepartie= 10019816 and sicovam=t.sicovam) OR lower(t.libelle) LIKE '%fees linked to p%'))
)
)
OR
(pims.value not like 'P%')
);
答案 0 :(得分:2)
查询很长,语法不是最好的,因此很难对其进行分析。
我的建议是:
1.在子查询中删除子t.sicovam IN
的子查询,在主查询中使用相同的表,这样你就可以在条件正常的情况下获得结果。
2.第二个问题是like
和or
如果您需要更多帮助,请将您的查询重写为更好的连接语法,发布表格模式,并简要描述您想要实现的目标。