Which SQL statement is faster? (HAVING vs. WHERE…)

后端 未结 8 1585
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-02 20:18
SELECT NR_DZIALU, COUNT (NR_DZIALU) AS LICZ_PRAC_DZIALU
    FROM  PRACOWNICY
    GROUP BY NR_DZIALU
    HAVING NR_DZIALU = 30

or

SE         


        
8条回答
  •  情深已故
    2020-12-02 20:30

    It might depend on the engine. MySQL for example, applies HAVING almost last in the chain, meaning there is almost no room for optimization. From the manual:

    The HAVING clause is applied nearly last, just before items are sent to the client, with no optimization. (LIMIT is applied after HAVING.)

    I believe this behavior is the same in most SQL database engines, but I can't guarantee it.

提交回复
热议问题