SQL中count()的不同用法

1.count(*):统计所有列的行数,包括均为null值的行;
2.count(1):统计所有列的行数,包括均为null值的行;
3.count(列名):统计指定列的行数,不包括null值;
实例:

a b c
2014 B 9
2015 A 8
2014 A 10
NULL C NULL
select count(*) from tb_name;

结果:4

select count(1) from tb_name;

结果:4

select count(a) from tb_name;

结果:3

关于不同用法性能比较,可参考这篇文章:
文章链接

猜你喜欢

转载自blog.csdn.net/p1306252/article/details/132297124