Home >Database >Mysql Tutorial >What is the usage of mysql having?
What is the usage of mysql having?
mysql having usage is:
In mysql, when we use aggregate functions, such as sum, count, and need to filter conditions, having This comes in handy, because WHERE filters records before aggregation, and having and group by are used in combination.
First query the statistical number of ids under the category cid
select cid,count(id) nums from table_name group by cid
The results are as follows:
Then you can use having to further filter the statistical data , such as a number where nums is greater than 2
select cid,count(id) nums from xzyd_question group by cid HAVING nums>2
Note: The judgment field after having must be the result returned by the aggregate function
Recommended tutorial: "mysql video tutorial"
The above is the detailed content of What is the usage of mysql having?. For more information, please follow other related articles on the PHP Chinese website!