Hive group by with cube and group by in same query

时间:2015-08-28 19:12:14

标签: hadoop hive hql hiveql

说我正在观察表模式如下的超速事​​件:

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;

只是想知道是否有一种方法可以在蜂巢中产生这种结果?

1 个答案:

答案 0 :(得分:1)

所以我要回答我自己的问题,我的想法是找到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)...);