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

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

    Saying they would optimize is not really taking control and telling the computer what to do. I would agree that the use of having is not an alternative to a where clause. Having has a special usage of being applied to a group by where something like a sum() was used and you want to limit the result set to show only groups having a sum() > than 100 per se. Having works on groups, Where works on rows. They are apples and oranges. So really, they should not be compared as they are two very different animals.

提交回复
热议问题