您的位置:首页 > Web前端

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

2016-10-11 18:55 1911 查看
在执行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的时候使用别名,就能够执行过去啦~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐