Aggregate functions in SQL Server

Source: Internet
Author: User

Aggregation function: A function that summarizes multirow (row) data into a row according to certain rules, and before summarizing the data, you can group the data by a specific column (Coloumn) and then filter by the criteria given again.

A: Count function
1 SELECT COUNT (Birthday) from customer
2 SELECT COUNT (*) from customer
3 SELECT COUNT (1) from customer
1 and 2 differences: Using a specific column name as a parameter, the column does not calculate the null value of the column within count
Both 2 and 3 compute NULL, and get the full number
You can also use distinct to calculate the number of each column for each of the same values within count

Two: Avg (), Sum (), Max () and Min () functions
These functions have the same syntax and parameters in addition to their functions.

HAVING clause:
The HAVING clause cannot follow the alias that appears in the SELECT statement, but the expression within the SELECT statement must be written again
That is: The HAVING clause cannot follow the alias that appears in the SELECT statement, or the variable name
Of course the most powerful thing about having clauses is that they can use an aggregate function as an expression, which is not allowed by the WHERE clause

A good aggregation function can be used to move a lot of tasks that are placed in the application business layer to the database, which is of great benefit to performance and maintenance.

Aggregate functions in SQL Server

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.