sql 根据条件count 问题

图片说明

碰到各奇怪的问题 如上图 下面两条 sql 得到的 count 加起来为啥不等于第一条的? 第一条得出 832 第二条得出 225 第三条得出 603 ;

看下字段status是不是存在null的情况,可能漏掉了null的数据

注意status字段的null,空,tab等,你可以对status去重查询下,看有几种情况就知道了;

select count(*) form order1 where is_test is null and status is null
还有一种status为空的情况,你这个应该是有为空的情况

后面两条的数据加起来应该等于
select count(*) form order1 where is_test is null and status is not null

还有一种status为空的情况,你这个应该是有为空的情况

607+225 = 832 擦看错了

stats !=0 在sql里面是不包括 stats is null 这种情况的

你这逻辑写得不对,所以数据不对称。

你可以先统计一下status都有什么状态:select status,count(* ) rom order 1 where is_test is null ,然后再穷举。