简体   繁体   English

MySQL NOT IN查询给出错误结果

[英]MySQL NOT IN query giving wrong results

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

Result : 1600 结果:1600

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);

Result : 0 结果: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);

Result : 0 结果:0

Ideally, sum of results for query 2 an 3 should be equal to result of query 1. Or there is some issue while comparing with NULL. 理想情况下,查询2和3的结果总和应等于查询1的结果。或者与NULL比较时存在一些问题。

IN() can not handle NULL values. IN()无法处理NULL值。 Instead use IS 改为使用IS

and id is not NULL

or 要么

and id is NULL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM