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

后端 未结 8 1586
佛祖请我去吃肉
佛祖请我去吃肉 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:47

    "WHERE" is faster than "HAVING"!

    The more complex grouping of the query is - the slower "HAVING" will perform to compare because: "HAVING" "filter" will deal with larger amount of results and its also being additional "filter" loop

    "HAVING" will also use more memory (RAM)

    Altho when working with small data - the difference is minor and can absolutely be ignored

提交回复
热议问题