三、聚合函数count和count_big的区别?
count_big的用法与count 函数类似。两个函数唯一的差别是它们的返回值。count_big始终返回 bigint 数据类型值。count始终返回 int 数据类型值。
四、应用实例
if object_id('[tb]') is not null drop table [tb]create table [tb] (id int,num int)insert into [tb]select 1,92 union allselect 2,94 union allselect 3,96 union allselect 4,98 union allselect 5,100--求个数select count(*) as 行数from [tb] /*5*/--求总和select sum(num) as 总和from [tb] /*480*/--求最大值select max(num) as 最大值from [tb] /*100*/--求最小值select min(num) as 最小值from [tb] /*92*/--求平均值select avg(num) as 平均值from [tb] /*96*/--求方差select var(num) as 方差from [tb] /*10*/--求总体方差select varp(num) as 总体方差from [tb] /*8*/--求标准偏差select stdev(num) as 标准偏差from [tb] /*3.16227766016838*/--求总体标准偏差select stdevp(num) as 总体标准偏差from [tb] /*2.82842712474619*/--求校验和select checksum_agg(num) as 校验和from [tb] /*100*/--求个数select count_big(num) as 行数from [tb] /*5*/--groupingselect isnull(ltrim(id),'合计') as id, sum(num) as num, grouping(id) as 'sgin'from [tb] group by id with rollup/*id num sgin------------ ----------- ----1 92 02 94 03 96 04 98 05 100 0合计 480 1*/