In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about the use of having in the mysql database, analyze and describe it from a professional point of view. I hope you can get something after reading this article.
Having sentences allow us to filter all kinds of data after grouping. Where sentences filter records before aggregation, that is, they act in front of group by and having sentences. The having clause filters the group records after aggregation.
First query the statistical number of id under category cid
The results of select cid,count (id) nums from table_name group by cid are as follows:
You can then use having to further filter the statistical data, such as numbers with nums 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.
Add:
The difference between where clause and having clause:
1.where cannot be put behind group by
2.having is used in conjunction with group by and placed behind group by, which is equivalent to where.
There can be no aggregate functions in the conditions after 3.where, such as SUM (), AVG (), etc., while HAVING can.
I. where clause
Where clause: the where clause is only used for the value returned from the from clause. Every row of data returned by the from clause is judged and filtered by the conditions in the where clause. Comparison operators and logical operators are allowed in the where clause.
II. Having clause
Having clause: the having clause is usually used with the order by clause because the role of having is to further filter the results of grouping statistics using group by.
The above is the use of having in the mysql database shared by the editor. If you have similar doubts, you might as well refer to the above method to try. If you want to know more about it, please follow the industry information.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.