我是sql新手。我该如何在不使用存在的情况下重写以下脚本
select
distinct oe.*,
o.*,
so.*,
ro.*
from
ms_bvoip_order_extension oe
inner join ms_order o on oe.ms_order_id = o.ms_order_id
inner join ms_sub_order so on so.ms_order_id = o.ms_order_id
inner join ms_job j on j.entity_id = so.ms_sub_order_id
inner join ms_task t on t.wf_job_id = j.wf_job_id
where
o.order_type = 900
and o.entered_date between to_date('12/01/2018 00:00:00', 'mm/dd/yyyy hh24:mi:ss')
and to_date('12/31/2018 00:00:00', 'mm/dd/yyyy hh24:mi:ss')
and j.entity_type = 5
and exists (
select
'X'
from
ms_task t
where
(
(t.name like '%Error%')
or (t.name like '%Correct%')
or (t.name = '%Create AOTS Ticket%')
)
and t.job_id = hextoraw(j.wf_job_id)
)
order by
o.usrp_order_number;
答案 0 :(得分:1)
如杰里所说,您可以使用EXISTS,但是如果您不想这样做,可以加入相同的EXISTS子查询:
INNER JOIN (
SELECT DISTINCT hextoraw(j.wf_job_id) JOB_ID
FROM ms_task
WHERE t.name like '%Error%'
or t.name like '%Correct%'
or t.name like '%Create AOTS Ticket%'
) TASK ON t.job_id = TASK.JOB_ID
您可能会删除其他ms_task表,并在j.wf_job_id
上加入JOIN ...