很奇怪,同一个表,运行下面三个语句,结果竟然不同!!!

莫鸣 2013-02-27 06:33:32
select count(*) from yeezong where 状态='已缴费'
select count(*) from yeezong
select count(*) from yeezong where 状态<>'已缴费'
在一个表中,状态有很多,不等于已缴费+已缴费=总和才对。但是结果,不等于已缴费的。竟然少很多。为什么呢?
上面查询
结果是:
776 ;
886 ;
9
为什么呢?
...全文
446 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoxiangqing 2013-02-28
  • 打赏
  • 举报
回复
状态栏里面有null值
莫鸣 2013-02-28
  • 打赏
  • 举报
回复
查看到了,用 select 状态,count(1) from yeezong group by 状态 谢谢。。
Mr_Nice 2013-02-28
  • 打赏
  • 举报
回复
引用 10 楼 diaodiaosky 的回复:
null也查询过,也找不到。最后直接去后台,一个个找到没有状态的,也就是空值的也加上一个状态,完事。谢谢大家的回答。但还是想问:如果是空值。用select count(*) from yeezong 状态<>'已缴费';应该也出来才是吧?
null 不等价于 '' 状态<>'已缴费',null是无法与'已缴费'进行<> 判断的哦。
Mr_Nice 2013-02-28
  • 打赏
  • 举报
回复
引用 楼主 diaodiaosky 的回复:
select count(*) from yeezong where 状态='已缴费' select count(*) from yeezong select count(*) from yeezong where 状态<>'已缴费' 在一个表中,状态有很多,不等于已缴费+已缴费=总和才对。但是结果,不等于已缴费的。竟然少很多。为什么呢? 上面查询 结果是: ……
看看这个运行了是啥结果.
select 状态,count(1) from yeezong group by 状态
莫鸣 2013-02-28
  • 打赏
  • 举报
回复
null也查询过,也找不到。最后直接去后台,一个个找到没有状态的,也就是空值的也加上一个状态,完事。谢谢大家的回答。但还是想问:如果是空值。用select count(*) from yeezong 状态<>'已缴费';应该也出来才是吧?
ZXUN_XUE 2013-02-28
  • 打赏
  • 举报
回复
肯定存在状态不一致的数据
叶子 2013-02-27
  • 打赏
  • 举报
回复
引用 楼主 diaodiaosky 的回复:
select count(*) from yeezong where 状态='已缴费' select count(*) from yeezong select count(*) from yeezong where 状态<>'已缴费' 在一个表中,状态有很多,不等于已缴费+已缴费=总和才对。但是结果,不等于已缴费的。竟然少很多。为什么呢? 上面查询 结果是: ……

select count(*) from yeezong 

select count(*) from yeezong where 状态='已缴费'
select count(*) from yeezong where 状态<>'已缴费'
select count(*) from yeezong where 状态 is null
發糞塗牆 2013-02-27
  • 打赏
  • 举报
回复
1、null值情况可能性最大。 2、select distinct 状态 from yeezong 就知道是不是第一个原因了
szm341 2013-02-27
  • 打赏
  • 举报
回复
应该是null值作祟~刚想来着,想其他情况的时候又给忘了
KevinLiu 2013-02-27
  • 打赏
  • 举报
回复
引用 4 楼 Vidor 的回复:
select count(*) from yeezong where isnull(状态,'')<>'已缴费'
同意有NULL值存在。
Vidor 2013-02-27
  • 打赏
  • 举报
回复
select count(*) from yeezong where isnull(状态,'')<>'已缴费'
Vidor 2013-02-27
  • 打赏
  • 举报
回复
状态 = NULL
create table #(stat varchar(10))
insert # select '已缴费'
insert # select '未缴费'
insert # select null

select count(*) from # where stat = '已缴费'
select count(*) from # where stat <> '已缴费'
select count(*) from #
szm341 2013-02-27
  • 打赏
  • 举报
回复
是不是你查询的时候数据发生了变化啊~ select * from yeezong where id not in( select id from yeezong where 状态='已缴费' )
莫鸣 2013-02-27
  • 打赏
  • 举报
回复
加问:如何查询得那些不出来的信息。

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧