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的时候使用别名,就能够执行过去啦~


你可能感兴趣的:(Hive)