Usually we have several commonly used aggregate functions to calculate the data for a table in a database
1, Count: counting
2. Sum: Calculate sum
3, Avg: Averaging
4, Max: Take maximum value
5, min: Take the minimum value
6, IsNull: When the return data is empty, the default setting is 0
7, COALESCE: When the return data is empty, the default setting is 0
1. Use of Count
Here is all the data for a student table
1) Calculate the number of data in the table, COUNT (*), return the result of the knot is 6
2) The number of address data in the Count table, count (address), the return result is 5
2, the use of sum
1) Calculate the total age
3. Use of AVG
1) Calculate the average age in the table
4. Use of Max
1) Calculate maximum age
5, Min's use
1) Calculate minimum age
When the data for an aggregate function query is NULL, it is returned null
For example: Calculate the sum of the ages of id>9
6, the use of IsNull
1) Calculate sum, we want no data to return 0 instead of returning NULL
7, the use of coalesce
1) Calculate sum, we want no data to return 0 instead of returning NULL
SQL Server aggregate function sum computed as NULL, how to return 0