Home >Database >Mysql Tutorial >What does having mean in mysql
HAVING clause is used to filter the aggregation results of grouped data. The following example illustrates its usage: after grouping customer sales data, only select customers whose total sales are greater than 10,000. The functions are different: the WHERE clause filters individual rows, and the HAVING clause filters aggregate values. The order of execution is different: WHERE is executed first, HAVING is executed later. Aggregation functions can be used to improve performance and provide more flexible filtering conditions.
HAVING clause in MySQL
What is the HAVING clause?
The HAVING clause is used to filter the results of aggregate functions. It is only used after the GROUP BY clause to perform conditional filtering on grouped data.
Syntax of HAVING clause
<code>SELECT 聚合函数(列名) FROM 表名 GROUP BY 分组列名 HAVING 条件</code>
Conditions can be comparison operators, logical operators and aggregate functions.
The following example illustrates the use of the HAVING clause:
<code class="sql">SELECT SUM(sales) AS 总销售额 FROM 订单 GROUP BY 客户ID HAVING 总销售额 > 10000;</code>
This query will select only those whose total sales are greater than 10,000 after grouping the customer sales data customer of.
The difference between HAVING and WHERE
Advantages of the HAVING clause
The above is the detailed content of What does having mean in mysql. For more information, please follow other related articles on the PHP Chinese website!