MySQL's HAVING keyword is used after GROUP BY to filter the grouped results and select only rows that meet the specified conditions. Syntax: SELECT
FROM GROUP BY HAVING It allows applying conditions to grouped columns, aggregate function results, or expressions.
The use of the HAVING keyword in MySQL
The HAVING keyword is used in MySQL in the GROUP BY subsection statement to apply the condition on the grouped data. It allows filtering of grouped results to select only rows that meet specified criteria.
Syntax
<code class="sql">SELECT <column_list> FROM <table_name> GROUP BY <group_by_column> HAVING <condition></code>
How to use
Example
For example, to find salespeople with sales of more than $1,000 from the "sales" table, you would use the following query:
<code class="sql">SELECT salesperson_name, SUM(sales_amount) AS total_sales FROM sales GROUP BY salesperson_name HAVING total_sales > 1000;</code>
In this query:
Note:
The above is the detailed content of What does having in mysql do?. For more information, please follow other related articles on the PHP Chinese website!