3

这让我大吃一惊。

我想做的就是在长varchar字段上进行基本的字符串比较。

我有一张大约的桌子。1200 万条记录。

如果我查询MY_FIELD='a string',我会得到 25947 的计数,这似乎是正确的。

如果我查询MY_FIELD!='a string',我得到的计数是 989。

这 2 个计数不应该等于 12M 的全表大小吗?

4

1 回答 1

6

这些行中有多少MY_FIELD设置为NULL

a. select count(*) from mytable;
b. select count(*) from mytable where my_field is null;
c. select count(*) from mytable where my_field is not null;
d. select count(*) from mytable where my_field = 'some value';
e. select count(*) from mytable where my_field != 'some value';

NULL不等于或不等于任何值,包括NULL所以我希望d+e等于cb+c等于a.

于 2010-11-03T14:06:35.067 回答