很奇怪,同一个表,运行下面三个语句,结果竟然不同!!!
select count(*) from yeezong where 状态='已缴费'
select count(*) from yeezong
select count(*) from yeezong where 状态<>'已缴费'
在一个表中,状态有很多,不等于已缴费+已缴费=总和才对。但是结果,不等于已缴费的。竟然少很多。为什么呢?
上面查询
结果是:
776 ;
886 ;
9
为什么呢?
[解决办法]
1、null值情况可能性最大。
2、select distinct 状态 from yeezong 就知道是不是第一个原因了
[解决办法]
select count(*) from yeezong
select count(*) from yeezong where 状态='已缴费'
select count(*) from yeezong where 状态<>'已缴费'
select count(*) from yeezong where 状态 is null
[解决办法]
肯定存在状态不一致的数据
[解决办法]
看看这个运行了是啥结果.
select 状态,count(1) from yeezong group by 状态
[解决办法]
null 不等价于 ''
状态<>'已缴费',null是无法与'已缴费'进行<> 判断的哦。