what's the difference between WHERE and HAVING

前端 未结 5 921
孤街浪徒
孤街浪徒 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

    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.

提交回复
热议问题