码迷,mamicode.com
首页 > Web开发 > 详细

json 转多行

时间:2021-04-21 11:55:30      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:length   class   tab   _id   rom   ext   use   sub   lan   

json字段格式

{
    "a": {
        "10000": 11,
        "20000": 22
    },
    "b": {
        "10000": 14,
        "20000": 255
    }
}


with
     q as (
         select t.member_id,
                replace(t.prod_code, ‘"‘) as prod_code ,
                replace(replace(t.score_use, "{"), ‘}‘) as score_use
         from (
            select member_id,prod_code, score_use
            from (select member_id, extra_json from ods_tables)
                    lateral view explode(
                            str_to_map(
                                substr(extra_json, 2, length(extra_json) -2)
                                , ‘},"‘
                                )
                        ) t as prod_code, score_use
         ) t
     )
select q.member_id, tmp.gcode, tmp.score from q lateral view explode(str_to_map(q.score_use)) tmp as gcode,score

json 转多行

标签:length   class   tab   _id   rom   ext   use   sub   lan   

原文地址:https://www.cnblogs.com/blogabc/p/14676090.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!