#Advanced Four: Common Functions-Grouping Functions
Category:
sum,avg,max,min,count
Features:
1. sum, avg are generally used to deal with numerical
max, min, count and can handle any type
2. The above grouping functions ignore NULL values
3. Can be
combined with distinct to achieve de- duplication operations 4. A separate introduction of count function is
general Use count(*) to count the number of rows
5. The field required for querying with the grouping function is the field after the group by
#------------------------------------------
#1. Simple to use
SELECT ROUND(AVG(salary),2) FROM employees;
#2. What types of parameters are supported
SELECT MAX(last_name) FROM employees;
SELECT MIN(last_name) FROM employees;
#3. Match with distinct
SELECT COUNT(DISTINCT(salary)),COUNT(salary) FROM employees;
#4. Detailed introduction of the count function
SELECT COUNT(*) FROM employees;
SELECT COUNT(1) FROM employees;
#test
SELECT MAX(salary),MIN(salary),AVG(salary),SUM(salary) FROM employees;
SELECT DATEDIFF(MAX(hiredate),MIN(hiredate)) diffrence FROM employees;
SELECT SUM(department_id=90) FROM employees;