MySQL's aggregation function

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.