sql中count(0)是什么意思?

来源:百度知道 编辑:UC知道 时间:2024/06/07 23:46:14
帮我看看这条语句select count(0) as user_total from(select distinct User_id from xyqj_log)
这条是将不重复的User_id的个数进行统计并保存在user_total中 这里面的count(0)怎么理解 这个0是什么意思

意思和count(*)或者count(column)是一样的
但是据说有个效率问题
因为COUNT(*)不单会进行全表扫描,也会对表的每个字段进行扫描。而COUNT('x')或者COUNT(COLUMN)或者COUNT(0)等则只进行一个字段的全表扫描

其他的count(*)、count(某字段)就不再解释,想必大家都明白,那么count(0)是什么意思呢?经过本人亲自测试过,count(0)是和count(*)效果一样的,都是统计某个表的记录的总行数。最后附上实例
select count(0) from tv3_gis_dictionary 结果:count(0)29
select count(*) from tv3_gis_dictionary 结果:count(*)29

count(0) as user_total 的意思是说查出来的count(0)数据用user_total作字段名字。也就是字段名取别名。
而count(0)和count(*)是一样的,count(*)你明白是什么吧。统计行数。

第一个字段