sql语句中count(1)和count(字段名)的区别

count(1)会统计包括null值的所有符合条件的字段的条数
count(字段名)统计非null值的所有符合条件的字段的条数

比如:
tb_source表中数据
在这里插入图片描述
count(1)统计当type=3时source_name的条数

select count(1) from tb_source where type=3

在这里插入图片描述
count(字段名)统计type=3时source_name的条数

select count(source_name) from tb_source where type=3

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_40626699/article/details/85249709
今日推荐