当前位置:网站首页>What are the SQL aggregate functions

What are the SQL aggregate functions

2022-06-25 01:56:00 Full stack programmer webmaster

Hello everyone , I meet you again , I'm your friend, Quan Jun .

 Aggregate functions are functions that perform calculations on a set of values and return a single value , It is often associated with SELECT Of the statement GROUP BY Clauses are used together ,SQL SERVER  What aggregate functions are there in the ? Let's take a look at them one by one :
1. AVG   Returns the average value in the specified group , Null values are ignored .
     example :select  prd_no,avg(qty) from sales group by prd_no

2. COUNT   Returns the number of items in the specified group .
       example :select  count(prd_no) from sales 

3. MAX   Returns the maximum value of the specified data .
       example :select  prd_no,max(qty) from sales group by prd_no 

4. MIN   Returns the minimum value of the specified data .
       example :select  prd_no,min(qty) from sales group by prd_no

5. SUM   Returns the sum of the specified data , Can only be used for numeric Columns , Null values are ignored .
       example :select  prd_no,sum(qty) from sales group by prd_no

6. COUNT_BIG   Returns the number of items in the specified group , And COUNT The function is different from COUNT_BIG return bigint value , and COUNT The return is int value .
      example :select  count_big(prd_no) from sales

7. GROUPING   Generate an additional column , When used CUBE or ROLLUP Operator to add a row , The output value is 1. When the added line is not by CUBE or ROLLUP When it comes into being , The output value is 0.
      example :select  prd_no,sum(qty),grouping(prd_no) from sales group by prd_no with rollup

8. BINARY_CHECKSUM   Returns the binary check value calculated on the row or expression list in the table , Used to detect changes to rows in a table .
      example :select  prd_no,binary_checksum(qty) from sales group by prd_no

9. CHECKSUM_AGG   Returns the check value of the specified data , Null values are ignored .
      example :select  prd_no,checksum_agg(binary_checksum(*)) from sales group by prd_no

10. CHECKSUM   Returns the check value calculated on the row of the table or on the expression list , Used to generate hash index .

11. STDEV   Returns the statistical standard deviation of all values in a given expression .
      example :select  stdev(prd_no) from sales

12. STDEVP   Returns the filled statistical standard deviation of all values in a given expression .
      example :select  stdevp(prd_no) from sales

13. VAR   Returns the statistical variance of all values in a given expression .
      example :select  var(prd_no) from sales

14. VARP   Returns the statistical variance of the population of all values in a given expression .
      example :select  varp(prd_no) from sales

Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/151864.html Link to the original text :https://javaforall.cn

原网站

版权声明
本文为[Full stack programmer webmaster]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206242058576159.html