what's the difference between WHERE and HAVING

前端 未结 5 830
孤街浪徒
孤街浪徒 2021-02-07 02:31

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

相关标签:
5条回答
  • 2021-02-07 03:04

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

    0 讨论(0)
  • 2021-02-07 03:04

    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.

    0 讨论(0)
  • 2021-02-07 03:10

    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.

    Follow the link for more detail https://www.codeproject.com/Articles/25258/Where-Vs-Having-Difference-between-having-and-Wher

    0 讨论(0)
  • 2021-02-07 03:13

    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.

    0 讨论(0)
  • 2021-02-07 03:17

    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.

    0 讨论(0)
提交回复
热议问题