what's the difference between WHERE and HAVING

坚强是说给别人听的谎言 提交于 2020-08-01 05:56:04

问题


It looks like both WHERE and HAVING help filter rows. I wonder if, instead of having to HAVING, I can use WHERE ... AND.

I'm a little confused.

Thanks for helping


回答1:


Explanation and query samples in this fine article: Where Vs Having / Difference between having and Where clause




回答2:


You use "WHERE" clauses to select rows for inclusion in the dataset before grouping operations have happend (GROUP BY). You use HAVING clauses to filter rows after grouping.

So like if you're aggregating a sum or a maximum or a minimum, you can use HAVING predicates to check the aggregated values on the candidate rows.




回答3:


There are some subtleties and intricacies, but quick description is a comparison: HAVING is to GROUP BY as WHERE is to SELECT.

In other words, if you think of HAVING as a WHERE clause that gets applied after the GROUP BY clause, things start to make sense.




回答4:


You would use the Having statement with Group By, typically as a way to filter on an aggregate column.

You can get more information here.




回答5:


Where clause is used to filter out rows from all over the database. But Having clause is used to filter out rows from a specific group of database. Having clause can also help in aggregate function like min/max/average.



来源:https://stackoverflow.com/questions/5011026/whats-the-difference-between-where-and-having

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!