Hive查询报错 Invalid table alias or column reference ‘create_time‘: (possible column names are: _c0, _c1

在执行Hive操作的时候有时候会遇到这种报错:

 Invalid table alias or column reference 'create_time': (possible column names are: _c0, _c1, _c2, _c3)

下面来分析这个条Hive语句:

select to_date(create_time) as time, count(*) as allNum, count(if(source=3,1,NULL)) as iosNum, count(if(source=4,1,NULL)) as androidNum 
from dg_cook  
where to_date(create_time)>='2016-08-10' and to_date(create_time)<='2016-10-10'  
group by to_date(create_time)   
order by to_date(create_time)
limit 1000

事实上Hive在执行完成group by之后其实已经默认吧以上所有的语句当成了一条,也就是说:

select to_date(create_time) as time, count(*) as allNum, count(if(source=3,1,NULL)) as iosNum, count(if(source=4,1,NULL)) as androidNum 
from dg_cook  
where to_date(create_time)>='2016-08-10' and to_date(create_time)<='2016-10-10'  
group by to_date(create_time)  

到最后执行完成,Hive把它当成一个语句,最后在order by to_date(create_time)时,Hive就不会识别到底啥是to_date(create_time)   

解决方案:

select to_date(create_time) as time, count(*) as allNum, count(if(source=3,1,NULL)) as iosNum, count(if(source=4,1,NULL)) as androidNum 
from dg_cook  
where to_date(create_time)>='2016-08-10' and to_date(create_time)<='2016-10-10'  
group by to_date(create_time)   
order by time  
limit 1000

order by的时候使用别名,就能够执行过去

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值