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
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...
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.