SQL Server中的聚合函數有哪些

2020-11-20 15:04:57

SQL Server中的聚合函數有:1、AVG;2、COUNT;3、MAX;4、SUM;5、COUNT_BIG;6、MIN;7、GROUPING;8、VAR;9、STDEV;10、VARP。

sql server中的聚合函數有:

(學習視訊分享:)

1、AVG 返回指定組中的平均值,空值被忽略。

例如:

select  prd_no,avg(qty) from sales group by prd_no

2、COUNT 返回指定組中專案的數量。

例如:

select  count(prd_no) from sales

3、MAX 返回指定資料的最大值。

例如:

select  prd_no,max(qty) from sales group by prd_no

4、MIN 返回指定資料的最小值。

例如:

select  prd_no,min(qty) from sales group by prd_no

5、SUM 返回指定資料的和,只能用於數位列,空值被忽略。

例如:

select  prd_no,sum(qty) from sales group by prd_no

6、COUNT_BIG 返回指定組中的專案數量,與COUNT函數不同的是COUNT_BIG返回bigint值,而COUNT返回的是int值。

例如:

select  count_big(prd_no) from sales

7、GROUPING 產生一個附加的列,當用CUBE或ROLLUP運運算元新增行時,輸出值為1.當所新增的行不是由CUBE或ROLLUP產生時,輸出值為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 返回指定資料的校驗值,空值被忽略。

例如:

select  prd_no,checksum_agg(binary_checksum(*)) from sales group by prd_n

10、CHECKSUM 返回在表的行上或在表示式列表上計算的校驗值,用於生成雜湊索引。

11、STDEV 返回給定表示式中所有值的統計標準偏差。

select  stdev(prd_no) from sales

12、STDEVP 返回給定表示式中的所有值的填充統計標準偏差。
例如:

select  stdevp(prd_no) from sales

13、VAR 返回給定表示式中所有值的統計方差。

例如:

select  var(prd_no) from sales

14、VARP 返回給定表示式中所有值的填充的統計方差。
例如:

select  varp(prd_no) from sales

相關推薦:

以上就是SQL Server中的聚合函數有哪些的詳細內容,更多請關注TW511.COM其它相關文章!