请教一个Hive中2列多行转成多列1行的问题?
把
转换成
把月份的值直接作为列名,谁会?
select date_format(order_day, 'MM') as month, sum(qty) as sum_qty from ( select 11 as order_id, '2022-01-02' as order_day, 1 as qty union all select 12 as order_id, '2022-02-02' as order_day, 2 as qty union all select 13 as order_id, '2022-03-02' as order_day, 3 as qty union all select 14 as order_id, '2022-04-02' as order_day, 4 as qty union all select 15 as order_id, '2022-04-02' as order_day, 5 as qty union all select 16 as order_id, '2022-05-02' as order_day, 6 as qty union all select 9 as order_id, '2021-01-02' as order_day, 6 as qty union all select 8 as order_id, '2021-02-06' as order_day, 7 as qty ) t1 group by date_format(order_day, 'MM')