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