Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between Having and Where in SQL

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article shows you what is the difference between Having and Where in SQL. The content is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Differential introduction:

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 where condition cannot contain a cluster function, and the where condition is used to filter out specific rows.

The function of the having clause is to filter the groups that meet the criteria, that is, to filter the data after the grouping, which often contains clustering functions, to filter out specific groups using having conditions, or to use multiple grouping criteria for grouping.

Note:

1. The HAVING clause must be located after GROUP BY and before ORDER BY.

2. The WHERE statement comes before the GROUP BY statement; SQL evaluates the WHERE statement before grouping.

3. The HAVING statement comes after the GROUP BY statement; SQL evaluates the HAVING statement after grouping.

Example:

Select category, sum (quantity) the sum of as quantity, from A group by category having sum (quantity) > 18

Example: joint use of Having and Where

Select category, SUM (quantity) from A where quantity > 8 group by category having SUM (quantity) > 10 what is the difference between Having and Where in SQL? have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report