我想知道这个查询的最佳替代查询是什么。 (从表现方面)
delete from CDR where anum not in (select msisdn from subs)
or bnum not in (select msisdn from subs)
如果您可以引入可以以相同方式工作的多个查询,那将是很好的。请考虑anum和bnum不能为空。
答案 0 :(得分:1)
也许这一个:
delete from
(select cdr.*
from cdr
left outer join subs a on a.msisdn = cdr.anum
left outer join subs b on b.msisdn = cdr.bnum
where a.msisdn is null or b.msisdn is null);
或
delete from cdr
where rowid <>all
(select cdr.rowid
from cdr
join subs a on a.msisdn = cdr.anum
join subs b on b.msisdn = cdr.bnum)
或
delete from cdr
where not exists
(select 'x'
from cdr
join subs a on a.msisdn = cdr.anum
join subs b on b.msisdn = cdr.bnum)
问题是你查询不存在的东西,因此总是很难 使用索引。