Polymerization
- 5 aggregation functions are available for fast statistical data
- COUNT (*) means that the total number of rows is computed, the parentheses are written with the name of the column, and the result is the same
- Query the total number of students
Select COUNT (*) from students;
- Max (column) indicates the maximum value for this column
- Max number of girls queried
Select Max (ID) from students where gender=0;
- Min (column) indicates the minimum value for this column
- Query the minimum number of students who have not been deleted
Select from where isdelete=0;
- The sum (column) indicates which of this column is calculated and
- After you've queried the boys ' numbers,
Select SUM (ID) from students where gender=1;
- AVG (column) indicates the average of this column
- Query does not remove the female number average
Select SUM (ID) from students where gender=1;
Group
- Group By field, indicating that the same data in this field is placed in a group
- After grouping, only the same data columns can be queried, and data columns that have differences cannot appear in the result set
- You can count the grouped data and do the aggregation operations.
- Grammar
Select column 1, column 2, aggregation ... from table name Group BY column 1, column 2, column 3 ....
- Number of men and women queried
Select Gender as Gender, COUNT (*) from studentsgroup by gender;
Check the number of cities
MySQL database basic usage-aggregation-grouping