天天看点

mysql 中int为null值 进行的比较

3 月,跳不动了?>>>

mysql 中int为null值 进行的比较
mysql 中int为null值 进行的比较

起始sql

select * from t_rabbit where sex = 0 and status = 0 and breed_count <= 3 AND is_grow = 1 
AND father_id <> 4
           

查询结果

mysql 中int为null值 进行的比较

null是查不出的

判断式中,不论 null =0 还是null <> 0 ,结果都是false。

所以改成这样比较好

最终sql:

select * from t_rabbit where sex = 0 and status = 0 and breed_count <= 3 AND is_grow = 1 
AND ( father_id <> 4 or father_id is null )