Home >Database >Mysql Tutorial >What is the usage of mysql having?

What is the usage of mysql having?

coldplay.xixi
coldplay.xixiOriginal
2020-06-23 16:39:485380browse

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.

What is the usage of mysql having?

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:

What is the usage of mysql having?

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

What is the usage of mysql having?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn