Postgresql 博士后;不在「;操作员使用

Postgresql 博士后;不在「;操作员使用,postgresql,postgresql-9.1,Postgresql,Postgresql 9.1,在我的数据库中,当我运行以下查询时,我得到1077作为输出 select count(distinct a_t1) from t1; 然后,当我运行这个查询时,我得到459 select count(distinct a_t1) from t1 where a_t1 in (select a_t1 from t1 join t2 using (a_t1_t2) where a_t2=0); 以上与此查询相同,也给出459: select count(distinct a_t1) from

在我的数据库中,当我运行以下查询时,我得到1077作为输出

select count(distinct a_t1) from t1;
然后,当我运行这个查询时,我得到459

select count(distinct a_t1) from t1 
where a_t1 in (select a_t1 from t1 join t2 using (a_t1_t2) where a_t2=0); 
以上与此查询相同,也给出459:

select count(distinct a_t1) from t1 join t2 using (a_t1_t2) where a_t2=0
但当我运行此查询时,得到的是0,而不是我所期望的618:

select count(distinct a_t1) from t1 
where a_t1 not in (select a_t1 from t1 join t2 using (a_t1_t2) where a_t2=0);
我正在运行PostgreSQL 9.1.5,这可能真的没有必要。请指出我在上述询问中的错误

更新1: 我创建了一个新表,并将上面子查询的结果输出到该表中。然后,我运行了一些查询:

select count(distinct a_t1) from t1
where a_t1 not in (select a_t1 from sub_query_table order by a_t1 limit 10);
万岁!现在我得到的答案是10!我能够将限额提高到450。之后,我又开始得到0

更新2:

sub_query_表中有459个值。最后,此查询为我提供了所需的答案:

select count(distinct a_t1) from t1
where a_t1 not in (select a_t1 from sub_query_table order by a_t1 limit 459);
其中,作为这一个,给出0作为答案:

select count(distinct a_t1) from t1
where a_t1 not in (select a_t1 from sub_query_table);

但是,为什么会发生这种情况

NOT IN运算符仅在NOT NULL上工作。值为null的列不匹配

select count(distinct a_t1) from t1 
where a_t1 not in (select a_t1 from t1 join t2 using (a_t1_t2) where a_t2=0) OR a_t1 IS NULL;

是的,但这只占a_t1的1个值,还有617个a_t1的其他值,我在上一次查询的结果中没有看到。@Phani不同的值是否可能减少计数?子列表中的所有条目都选择了相同的值吗?我不确定我是否遵循了你所说的。第一个查询显示有1077个不同的a_t1值。然后,第二次查询显示,在1077个值中,有459个不同的值出现在子查询的结果中。因此,子查询的结果中应该有618个不同的a_t1值。但是最后一个查询返回0,如果我用
或a_t1=0
更新它,我得到的结果是1。@我是否键入“或a_t1=0”或“或a_t1为空”?对不起。我确实使用了
或a_t1为NULL