在hive2.3.3中使用嵌套选择时,错误消息:“当前上下文中不支持tok\u allcolref”

ecfdbz9o  于 2021-06-27  发布在  Hive
关注(0)|答案(1)|浏览(679)

当我像这样使用嵌套的select-in-hive时

Select 
a.month,
a.day,
sum(a.pv)/count(a.*) 
from 
(Select month,day, remote_addr,count(1) as pv 
from ods_weblog_detail group by remote_addr,month,day) as a;

它返回错误消息:“tok\u allcolref在当前上下文中不受支持”。
但当我分别选择月、日和总和(a.pv)/计数(a*)时,如下所示:

Select 
sum(a.pv)/count(a.*) 
from 
(Select month,day, remote_addr,count(*) as pv from ods_weblog_detail group by remote_addr,month,day) as a;

或者这个:

Select 
a.month,a.day 
from 
(Select month,day, remote_addr,count(*) as pv 
from 
ods_weblog_detail 
group by remote_addr,month,day) as a;

两种说法都给了我正确的答案。那么为什么我不能在一个语句中同时选择这三个(a.month,a.day和sum(a.pv)/count(a.*)?谢谢!!!

4si2a6ki

4si2a6ki1#

查询缺少 group by .

Select 
a.month,
a.day,
sum(a.pv)/count(a.*) 
from (select month,day, remote_addr,count(1) as pv 
      from ods_weblog_detail 
      group by remote_addr,month,day
     ) a
group by a.month,a.day

查询也可以简化如下。

select month,day,remote_addr
,sum(count(*)) over(partition by month,day,remote_addr)/count(*) over(partition by month,day) as res
from ods_weblog_detail

相关问题