如果没有样本数据,这只是一个偶然的机会,但我会写下
NOT EXISTS
版本如下:
Select A.C_SEQUENCE, A.STATUS
FROM PROD.CONTROL A
where A.AID = 'BILLINGS'
and A.USER='GLOBAL_NETWORK'
--and A.STATUS = 'ON'
and NOT EXISTS
(
select *
from PROD.STATUS_R B
and A.C_SEQUENCE = B.H_SEQUENCE
and B.H_STAT in('IGN','ACK')
)
order by C_date DESC limit 5000
不存在
表示您只需要外部选择记录,其中子选择不返回记录。但实际上,由于子选择不包含太多外部选择中尚未包含的内容,因此最好这样编写:
Select A.C_SEQUENCE, A.STATUS
FROM PROD.CONTROL A
left exception join prod.status_r_b b
on b.h_sequence = a.c_sequence
and b.h_stat in ('IGN', 'ACK')
where A.AID = 'BILLINGS'
and A.USER='GLOBAL_NETWORK'
--and A.STATUS = 'ON'
order by C_date DESC limit 5000
您还应该能够简化
NOT IN
版本如下:
Select A.C_SEQUENCE, A.STATUS
FROM PROD.CONTROL A
where A.AID = 'BILLINGS'
and A.USER='GLOBAL_NETWORK'
--and A.STATUS = 'ON'
and A.C_SEQUENCE NOT IN
(
select B.H_SEQUENCE
from PROD.STATUS_R B
and B.H_STAT in('IGN','ACK')
)
order by C_date DESC limit 5000
在这种情况下
不在
确认可以返回行,但只能从中选择行
prod.control
其中序列号不在筛选的
prod.status_r
结果集。