HAVING clause is used to filter the grouped result set and is applied to the summarized data rather than the original data. It can discard rows that do not meet the criteria, refine the result set, and extract specific information. For example, this query finds orders with sales greater than $100: SELECT customer_id, SUM(amount) AS total_amount FROM orders GROUP BY customer_id HAVING total_amount > 100;
In MySQL, the meaning of HAVING
The HAVING clause is used to further filter the result set grouped by GROUP BY. It is similar to the WHERE clause, but applies to aggregated data rather than raw data.
Usage scenarios
The HAVING clause is usually used to filter out rows that meet specific conditions from grouped data. For example:
##Grammar
The syntax of the HAVING clause is as follows:<code>HAVING <条件></code>where
is any Valid SQL expressions can include aggregate functions (such as SUM, COUNT, etc.) and comparison operators (such as =, >, <, etc.).
Function
The HAVING clause can provide the following functions by filtering the grouped data:Example
The following example query finds sales greater than 100 USD orders:SELECT customer_id, SUM(amount) AS total_amount
FROM orders
GROUP BY customer_id
HAVING total_amount > 100;
This query returns the following results:
total_amount | |
---|---|
120.50 | |
150.75 | |
115.20 |
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!