In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
Today, I will talk to you about the difference between having and where in SQL. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
In a select statement, you can use the groupby clause to divide rows into smaller groups, then use the clustering function to return summary information for each group, and you can use the having clause to restrict the result set returned. The groupby clause groups query results and returns summary information for rows Oracle groups query results according to the value of the expression specified in the groupby clause. In a query statement with a groupby clause, the column specified in the select list is either the column specified in the groupby clause or contains the clustering function copy code as follows: selectmax (sal), jobempgroupbyjob
(note that max (sal), the job of job does not have to appear, but it makes sense.) the select and groupby,having clauses of the query statement are the only places where the where function occurs, and the cluster function cannot be used in the cluster clause. The copy code is as follows: selectdeptno,sum (sal) fromempwheresal > 1200groupbydeptnohavingsum (sal) > 8500orderbydeptno
When the having clause is used in the gropuby clause, only the groups that meet the having condition are returned in the query results. There can be where clause and having clause in a sql statement. Having is similar to the where clause, which is used to set the qualifying condition. The function of the where clause is to remove the rows that do not meet the where condition before grouping the query results, that is, to filter the data before grouping, the condition cannot contain a clustering function, and the where condition is used to display specific rows. The role of the having clause is to filter groups that meet the criteria, that is, to filter data after grouping, which often contains clustering functions, to display specific groups using having conditions, or to group using multiple grouping criteria. The copy code for querying the number of employees for each position in each department is as follows: selectdeptno,job,count (*) fromempgroupbydeptno,job
If you are still confused about when to use WHERE and when to use HAVING, follow these instructions: the WHERE statement comes before the GROUPBY statement; SQL evaluates the WHERE statement before grouping. The HAVING statement comes after the GROUPBY statement; SQL evaluates the HAVING statement after grouping.
After reading the above, do you have any further understanding of the difference between having and where in SQL? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
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.