二、sum count函数举例说明
create table test(A int,B int,info varchar(10))
go
insert into test(A,B,info)values(5,6,’A’),
(2,4,’B’),(8,9,’B’),(3,1,’A’),(7,3,’C’),(1,2,null)
go
select info,sum(1) as [sum(1)],
count(*) as [count(*)],
count(6) as [count(6)],
count(8) as [count(8)],
count(info) as [count列],
sum(2) as [sum(2)],
sum(A) as [sum列值]
from test
GROUP BY info
/*
从以上的sql脚本中,可以看出
sum(1)同count(*) count(6) count(8) count(info)都是统计行数,返回结果一致
—sum(2)对每一行采用值2相加
count(6) count(8) 不会由于输入的值不同而得到不同的值
—count(列) 会过滤掉列值等于null的行
及count(列名);只统计列值中不会null的行数
*/
go
truncate table test
drop table test