mySql count()函数

count()  仅仅是计算行数的.
仅仅当你 指定的列名里面, 有存在 NULL 的情况下,会对你的 COUNT 结果有影响。
下面是一个例子:

1> create table #t123(
2> id int,
3> val int
4> );
5> go
1> insert into #t123 values(1, null);
2> insert into #t123 values(null, 1);
3> insert into #t123 values(1, 1);
4> go

(1 行受影响)
1> select count(id), count(val), count(*), count(1) from #t123;
2> go

----------- ----------- ----------- -----------
          2           2           3           3
警告: 聚合或其他 SET 操作消除了 Null 值。

猜你喜欢

转载自lizhuang.iteye.com/blog/2190723
今日推荐