hive grouping sets 等聚合函數
阿新 • • 發佈:2018-02-12
union _id 說明 from div sele gpo 函數 grouping
函數說明:
grouping sets
在一個 group by 查詢中,根據不同的維度組合進行聚合,等價於將不同維度的 group by 結果集進行 union all
cube
根據 group by 的維度的所有組合進行聚合
rollup
是 cube 的子集,以最左側的維度為主,從該維度進行層級聚合。
-- grouping sets select order_id, departure_date, count(*) as cnt from ord_test where order_id=410341346 group by order_id, departure_dategrouping sets (order_id,(order_id,departure_date)) ; ---- 等價於以下 group by order_id union all group by order_id,departure_date -- cube select order_id, departure_date, count(*) as cnt from ord_test where order_id=410341346 group by order_id, departure_date with cube ;---- 等價於以下 select count(*) as cnt from ord_test where order_id=410341346 union all group by order_id union all group by departure_date union all group by order_id,departure_date -- rollup select order_id, departure_date, count(*) as cnt from ord_test where order_id=410341346 groupby order_id, departure_date with rollup ; ---- 等價於以下 select count(*) as cnt from ord_test where order_id=410341346 union all group by order_id union all group by order_id,departure_date
結果:grouping_sets, cube, rollup
hive grouping sets 等聚合函數