某些字段为空的行数加上非空的行数与总数的不同

  • 本文关键字:字段 sql-server-2005
  • 更新时间 :
  • 英文 :


我有一个表,我有一个可空blob字段类型(SQL SERVER 2005)用于存储图像。所以我有以下情况:

select count (*) from table where image_field is null返回180000行图像。

select count (*) from table where image_field is not null返回没有图像的3600000行。

如果我使用select count (*) from table,我没有3780000行(3600000 + 180000),但少一点。

谁能解释一下为什么会这样?

有人添加或删除了几行?

  Select Count(*) total,
     Sum(case when When image_field is null Then 1 Else 0 End) nullCount,
     Sum(case when When image_field is not null Then 1 Else 0 End) notNulCount
  From table

并将这些数字与单个查询

中的数字进行比较

最新更新