一、GROUPING SETS
Grouping sets允许用户指定要分组的多个列列表。将不属于分组列的给定字列表的列设置为NULL
比如,需求分别按照店铺分组、订单组分组、店铺和订单组分组统计订单销售额,并获取三者的结果集(插入到宽表)。可以通过union all 多个group by来实现
select store_id,
null,
sum(coalesce(order_amount, 0))
from yp_dwb.dwb_order_detail
group by store_id
union all
select null,
group_id,
sum(coalesce(order_amount, 0))
from yp_dwb.dwb_order_detail
group by group_id
union all
select store_id,
group_id,
sum(coalesce(order_amouunt, 0)