您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

mysql 列转行 并进行json截取(mysql 5.6)

bubuko 2022/1/25 20:00:31 mysql 字数 6963 阅读 652 来源 http://www.bubuko.com/infolist-5-1.html

如为8.0以上版本,可以直接使用原生的json解析器处理,低版本不支持 select t1.* ,concat(replace(substr(result,instr(result,'"url":"') +7,instr(result,'"}')-instr(result,'"url":"') -7 ...

 

如为8.0以上版本,可以直接使用原生的json解析器处理,低版本不支持

 

select
     t1.*
    ,concat(replace(substr(result,instr(result,"url":") +7,instr(result,"})-instr(result,"url":") -7),https://,http://),@1500h)  as temp_image -- json数据截取
from (
    SELECT 
         t.*
        ,concat(substring_index(substring_index(t.image_file,"},{", b.help_topic_id + 1), "},{", -1),"}) as result -- 列转行
    FROM (
        SELECT
             a.id
            ,a.image_file -- json array string
        FROM table_a a
        where length(a.image_file) > 3
        limit 10,1
    ) t
    join (
        select 0 as help_topic_id union all
        select 1 as help_topic_id union all
        select 2 as help_topic_id union all
        select 3 as help_topic_id union all
        select 4 as help_topic_id union all
        select 5 as help_topic_id union all
        select 6 as help_topic_id union all
        select 7 as help_topic_id union all
        select 8 as help_topic_id union all
        select 9 as help_topic_id
    ) b 
        ON b.help_topic_id <  ((LENGTH(t.image_file) - LENGTH(REPLACE(t.image_file, "},{", ‘‘)))/5 + 1)
    order by result
) t1
;

 

mysql 列转行 并进行json截取(mysql 5.6)

原文:https://www.cnblogs.com/chenzechao/p/12625445.html


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶