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

The difference between where and having in Oracle

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

Share

Shulou(Shulou.com)06/01 Report--

First of all, where is for a single statement and having is for groups. And the priority is where > group by > having.

It is important to note that:

1.where cannot be put after group by.

2.having is used with group by and is put after group by

Functions cannot be aggregated after 3.where, that is, SUM (), AVG (), and so on. Having can.

Aggregate function:

Aggregate functions are statistical functions. Such as summation, average, maximum and minimum, and so on. Group by can act on these statistical functions on a set of data. For example, if I need to ask for the average of each stage, I need to classify each stage and then average it. Of course, where can also meet the requirements.

In the query, the priority of the aggregate statement (aggregate function) is higher than that of having (that is, it is classified first in statistics), and the priority of the aggregate statement is lower than where (), that is, it is filtered individually and then counted. For example, we need to screen for departments that are less than 20% and whose total salary is greater than 10000. Then:

Select department_id, sum (salary) from groupwhere department_id

< 20 group by department_idhaving sum(salary) >

10000

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