sql聚合函數(shù)有:1、AVG函數(shù);2、count函數(shù);3、MAX函數(shù);4、MIN函數(shù);5、SUM函數(shù);6、GROUPING函數(shù);7、CHECKSUM函數(shù);8、STDEV函數(shù);9、STDEVP函數(shù);10、var函數(shù);11、VARP函數(shù)等等。
SQL中的聚合函數(shù)有:指定組中的平均值的AVG函數(shù),返回組中項目的數(shù)量的COUNT函數(shù),返回數(shù)據(jù)最大值的MAX函數(shù),返回數(shù)據(jù)的和的SUM函數(shù)等
聚合函數(shù)是對一組值執(zhí)行計算并返回單一的值的函數(shù),它經(jīng)常與select語句的GROUP BY子句一同使用,SQL SERVER 中具體有哪些聚合函數(shù)呢?我們來一 一看下:
1. AVG? 返回指定組中的平均值,空值被忽略。
例:select? prd_no,avg(qty) from sales group by prd_no
2. COUNT? 返回指定組中項目的數(shù)量。
例:select? count(prd_no) from sales?
3. MAX? 返回指定數(shù)據(jù)的最大值。
例:select? prd_no,max(qty) from sales group by prd_no?
4. MIN? 返回指定數(shù)據(jù)的最小值。
例:select? prd_no,min(qty) from sales group by prd_no
5. SUM? 返回指定數(shù)據(jù)的和,只能用于數(shù)字列,空值被忽略。
例:select? prd_no,sum(qty) from sales group by prd_no
6. COUNT_BIG? 返回指定組中的項目數(shù)量,與COUNT函數(shù)不同的是COUNT_BIG返回bigint值,而COUNT返回的是int值。
例:select? count_big(prd_no) from sales
7. GROUPING? 產(chǎn)生一個附加的列,當用CUBE或ROLLUP運算符添加行時,輸出值為1.當所添加的行不是由CUBE或ROLLUP產(chǎn)生時,輸出值為0.
例:select? prd_no,sum(qty),grouping(prd_no) from sales group by prd_no with rollup
8. BINARY_CHECKSUM? 返回對表中的行或表達式列表計算的二進制校驗值,用于檢測表中行的更改。
例:select? prd_no,binary_checksum(qty) from sales group by prd_no
9. CHECKSUM_AGG? 返回指定數(shù)據(jù)的校驗值,空值被忽略。
例:select? prd_no,checksum_agg(binary_checksum(*)) from sales group by prd_no
10. CHECKSUM? 返回在表的行上或在表達式列表上計算的校驗值,用于生成哈希索引。
11. STDEV? 返回給定表達式中所有值的統(tǒng)計標準偏差。
例:select? stdev(prd_no) from sales
12. STDEVP? 返回給定表達式中的所有值的填充統(tǒng)計標準偏差。
例:select? stdevp(prd_no) from sales
13. VAR? 返回給定表達式中所有值的統(tǒng)計方差。
例:select? var(prd_no) from sales
14. VARP? 返回給定表達式中所有值的填充的統(tǒng)計方差。
例:select? varp(prd_no) from sales