[Teach Youself SQL in 10 Minutes] The difference between HAVING and WHERE

本文详细解释了SQL中HAVING子句与WHERE子句的区别。WHERE子句在数据分组前进行过滤,而HAVING子句则在数据分组后进行过滤。文中强调了正确使用这两个子句的重要性,并给出了具体的使用建议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

The difference between HAVING and WHERE Here's another way to look it: WHERE filters before data is grouped, and HAVING filters after data is grouped. This is an important distinction; rows that are eliminated by a WHERE clause will not be included in the group. This could change the calculated values which in turn could affect which groups are filtered based on the use of those values in the HAVING clause.

 

 

Using HAVING and WHERE HAVING is so similar to WHERE that most DBMSs treat them as the same thing if no GROUP BY is specified. Nevertheless, you should make that distinction yourself. Use HAVING only in conjunction with GROUP BY clauses. Use WHERE for standard row-level filtering.

 

 

BTW:

The only difference is that WHERE filters rows and HAVING filters groups.

The difference between HAVING and WHERE Here's another way to look it: WHERE filters before data is grouped, and HAVING filters after data is grouped.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值