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

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

    In Hive 0.11.0 and later, columns can be specified by position if hive.groupby.orderby.position.alias is set to true.

    set hive.groupby.orderby.position.alias=true;
    select Store_id as StoreId, count(*) as _count
    from StoreProduct
    group by 1
    

    I'm don't understand the purpose of your query. Given the context of the query you posted, your condition is not necessary because items that do not exist, i. e. count 0, will never be a result from a query...

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题