WHERE vs HAVING

后端 未结 7 2246
北荒
北荒 2020-11-22 08:20

Why do you need to place columns you create yourself (for example select 1 as \"number\") after HAVING and not WHERE in MySQL?

7条回答
  •  生来不讨喜
    2020-11-22 08:38

    The main difference is that WHERE cannot be used on grouped item (such as SUM(number)) whereas HAVING can.

    The reason is the WHERE is done before the grouping and HAVING is done after the grouping is done.

提交回复
热议问题