请教一个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')


#hive##大数据##阿里巴巴##腾讯#
全部评论
https://juejin.cn/post/7120945116172255263/ 答案
点赞 回复 分享
发布于 2022-07-16 20:28

相关推荐

10-25 00:32
香梨想要offer:感觉考研以后好好学 后面能乱杀,目前这简历有点难
点赞 评论 收藏
分享
冲芭芭拉鸭:你这图还挺新,偷了。
投递美团等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
3
分享
牛客网
牛客企业服务