Why can't I use an alias for an aggregate in a having clause?

后端 未结 8 1880
我在风中等你
我在风中等你 2020-12-02 14:26

My code is like shown below :

select col1,count(col2) as col7
from --some join operation
group by col1
having col7 >= 3 -- replace col7 by count(col2) to          


        
8条回答
  •  星月不相逢
    2020-12-02 15:05

    You should select twice to use the count() column

    select * from (select col1,count(col2) as col7
    from --some join operation
    group by col1) as temp
    where temp.col7 >= 3
    

提交回复
热议问题