我曾经犯的错误如下:
注意,红色字体的查询条件只能查询出pass_name!='batch'且不为null的字段(null不能和任何值比较,即使是null也不会是true),如果需要查询出pass_name是null的字段,必须显示的加上:or pass_name is NULL
SELECT COUNT(*) FROM 表名 WHERE FROM_UNIXTIME(submit_time) >= '2012-08-01' AND FROM_UNIXTIME(submit_time) < '2013-07-01' AND pass_name <> 'test'(错误)
查询出包含null且pass_name!='batch'的数据:
SELECT COUNT(*) FROM 表名 WHERE FROM_UNIXTIME(submit_time) >= '2012-08-01' AND FROM_UNIXTIME(submit_time) < '2013-07-01' AND (pass_name <> 'test' or pass_name is null)(正确查出pass_name!=null及pass_name是null的)