当我像这样在蜂巢中使用嵌套选择时
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_ALLCOLREF。”
但是当我分别选择a.month,a.day和sum(a.pv)/ count(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。*))?非常感谢!!!
答案 0 :(得分:0)
查询缺少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