The syntax for the aggregation operation is as follows:
--SELECT [field1,field2,...... fieldn] Fun_name
-From TableName
--[WHERE where_contition]
--[GROUP by Field1,field2,...... fieldn
--[with ROLLUP]]
--[Having where_contition]
--The following description of its parameters.
Fun_name represents the aggregation operation to be done, which is the aggregate function, which is commonly used with SUM, COUNT (*) (number of records), Max (maximum), min (minimum).
The group BY keyword indicates the fields to be aggregated by category, such as the number of employees to be classified by department, and the department should be written behind group by.
With ROLLUP is an optional syntax that indicates whether the aggregated results of the classification are re-aggregated.
The HAVING keyword indicates that the result of the classification is then filtered by the condition.
Note: The difference between having and where is that having is a condition of filtering the results of the aggregation, where the
--Filter the records before closing, and if the logic allows, we use where we can filter the records as much as possible, because the result
--set reduction, will be the efficiency of the polymerization greatly improved, and finally according to the logic to see if have to re-filter
--Select Deptno,count (1) from the EMP group by DEPTNO have count (1) >1;
--Statistics on total salary, maximum and minimum salary for all employees of the company:
--Select sum (SAL), Max (Sal), Min (sal) from EMP;
MySQL's aggregation function