如何把json里面的数值通过mysql查询提取出来

[{"soItemId": 2301060001221041, "verifyNum": 2, "productName": "【秒杀】思念大黄米小小汤圆组合装300g*2", "productPicPath": "/1672819676510_70.5334732755549_9b64dfd3-8d96-4407-8587-121a8dacbb0d.jpg"}, {"soItemId": 2301060001221042, "verifyNum": 1, "productName": "思念实惠装鸡蛋韭菜水饺2000g", "productPicPath": "/1660101547485_36.25299721501667_11ced960-d614-48c3-b510-2a7feb58ec04.jpg"}, {"soItemId": 2301060001221043, "verifyNum": 1, "productName": "安井香脆油条450g", "productPicPath": "/1658998405315_67.98591284632266_3ee9b47b-bb8f-48ca-877d-3a0c6243e54f.jpg"}, {"soItemId": 2301060001221045, "verifyNum": 1, "productName": "潮香村葱油饼500g", "productPicPath": "/1670230181437_38.009247676734404_ce29344c-14c3-4157-9038-c3f0220f8aad.png"}]

期望如下图结果

image.png

SQL 倾落~ 发布于 2023-3-24 17:03
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
0
倾落~Lv3见习互助
发布于2023-3-29 13:55

这样数据就可以清洗出来了

SELECT  SUBSTRING_INDEX( SUBSTRING_INDEX( a.product, ";", b.id + 1 ), ";",- 1 ) AS product_info,b.id,

JSON_EXTRACT(SUBSTRING_INDEX( SUBSTRING_INDEX(  a.product, ";", b.id + 1 ), ";",- 1 ), '$[0].soItemId') as soItemId,

JSON_EXTRACT(SUBSTRING_INDEX( SUBSTRING_INDEX(  a.product, ";", b.id + 1 ), ";",- 1 ), '$[0].verifyNum') as verifyNum,

replace(JSON_EXTRACT(SUBSTRING_INDEX( SUBSTRING_INDEX(  a.product, ";", b.id + 1 ), ";",- 1 ), '$[0].productName'),'"','') as productName

FROM

(select  REPLACE(REPLACE(REPLACE (sv.products,'}, {','};{'),'[',''),']',"") as product  from oms.so_verification_log sv 

WHERE sv.order_code='230106892753457395') a

JOIN bi.ls_keyid b 

on b.id < ( length(a.product) - length(replace( a.product, ";","" ) ) + 1)

image.png

最佳回答
0
1592Lv6高级互助
发布于2023-3-24 17:09
  • 1关注人数
  • 280浏览人数
  • 最后回答于:2023-3-29 13:55
    请选择关闭问题的原因
    确定 取消
    返回顶部