Hive group by with cube 和 group by 在同一个查询中
Hive group by with cube and group by in the same query
假设我正在观察 table 模式如下的超速事故:
create table speeding_data(
date_of_occurrence date,
year int,
make string,
model string,
speed int
);
我想观察这些特征的不同组合下的平均速度,但希望它始终按 date_of_occurrence
分组,例如可能是这样的
select date_of_occurrence, year, make, model, avg(speed)
from speeding_data
group by date_of_occurrence
group by year, make, model with cube;
只是想知道是否有办法在 hive 中产生这个结果?
所以我要回答我自己的问题,我的想法是使用 GROUPING SET
子句,我可以继续这样做:
select a, b, c, d, avg(e)
from tbl
group by a, b, c, d
grouping set ( (a), (a,b), (a,c), (a,d)...);
假设我正在观察 table 模式如下的超速事故:
create table speeding_data(
date_of_occurrence date,
year int,
make string,
model string,
speed int
);
我想观察这些特征的不同组合下的平均速度,但希望它始终按 date_of_occurrence
分组,例如可能是这样的
select date_of_occurrence, year, make, model, avg(speed)
from speeding_data
group by date_of_occurrence
group by year, make, model with cube;
只是想知道是否有办法在 hive 中产生这个结果?
所以我要回答我自己的问题,我的想法是使用 GROUPING SET
子句,我可以继续这样做:
select a, b, c, d, avg(e)
from tbl
group by a, b, c, d
grouping set ( (a), (a,b), (a,c), (a,d)...);