Why can't I use alias in a count(*) “column” and reference it in a having clause?

前端 未结 8 1847
一整个雨季
一整个雨季 2020-11-28 02:46

I was wondering why can\'t I use alias in a count(*) and reference it in the having clause. For instance:

select Store_id as StoreId, count(*) as _count
             


        
8条回答
  •  [愿得一人]
    2020-11-28 03:23

    You can use the alias for the aggregates in SQL, but that is just to show the alias in the results headers. But when you want to have a condition with the aggregate function in the having you still need to use the aggregate because it evaluates the function and not the name.

提交回复
热议问题