HAVING clause is used to filter aggregation results. The specific functions include: filtering grouped data and excluding groups that do not meet the conditions. Filtering nested aggregation based on multiple conditions
The role of the HAVING clause in MySQL
The HAVING clause is used to filter aggregate results, and it is used after the GROUP BY clause. The HAVING clause filters the conditions on the aggregate columns and selects only the aggregate result rows that meet the conditions.
Specific function:
Usage syntax:
<code>SELECT 聚合函数(列名) FROM 表名 GROUP BY 分组列 HAVING 聚合条件;</code>
Example:
<code>SELECT COUNT(*) AS 总数 FROM 订单 GROUP BY 客户ID HAVING COUNT(*) > 1;</code>
This query counts the order quantity of each customer, And filter out customers whose order quantity is greater than 1. The difference between
and WHERE clause:
The above is the detailed content of The role of having in mysql. For more information, please follow other related articles on the PHP Chinese website!