mysql 中int爲null值 進行的比較

起始sqlsql

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

查詢結果code

null是查不出的
判斷式中,不論 null =0 仍是null <> 0 ,結果都是false。
因此改爲這樣比較好blog

最終sql:it

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 )
相關文章
相關標籤/搜索