MySQL NOT IN查询给出错误结果

时间:2018-12-11 07:41:45

标签: mysql

select count(*) from call_log
where relation_id in (14,15)
and date(from_unixtime(created_time/1000)) = '2018-12-10';

结果:1​​600

select count(*) from call_log
where relation_id in (14,15)
and date(from_unixtime(created_time/1000)) = '2018-12-10'
and id not in (NULL);

结果:0

select count(*) from call_log
where relation_id in (14,15)
and date(from_unixtime(created_time/1000)) = '2018-12-10'
and id in (NULL);

结果:0

理想情况下,查询2和3的结果总和应等于查询1的结果。或者与NULL比较时存在一些问题。

1 个答案:

答案 0 :(得分:4)

IN()无法处理NULL的值。而是使用IS

and id is not NULL

and id is NULL