不在条款中,有没有更好的方法

not in clause, is there a better way

我试图排除以前见过的身份证号码,我的查询是

select id from table1 where date1 >= eDate1 and date1 <= eDate2 and zId = 256
and id no in
(select id from table1 where date1 < eDate1 and zId = 256)

MonetDB.

有没有更好的方法,我试图简单地排除在所选日期范围之前在区域中看到的任何 ID 号?

谢谢。

一些数据库优化器可以处理大的 id 列表,其他的则处理不好。

最好的方法是使用左连接并过滤未命中:

select a.id
from table1 a
left join table1 b on a.id = b.id and b.date1 < eDate1
where a.date1 between eDate1 and eDate2
and zId = 256
and b.id is null