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

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

    Probably because that's the way sql defines the namespaces. take, for example:

      select a as b, b as a
        from table
       where b = '5'
    order by a
    

    what do a and b refer to? The designers just chose to make the aliases only appear on the "outside" of the query.

提交回复
热议问题