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

前端 未结 8 1743
一整个雨季
一整个雨季 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:11

    Here is my contribution (based on the code posted here):

    select * from (
      SELECT Store_id as StoreId, Count(*) as StoreCount 
      FROM StoreProduct
      group by Store_id
      ) data
    where data.StoreCount > 0
    

提交回复
热议问题