数据库
首页 > 数据库> > mysql解析json下的某个字段

mysql解析json下的某个字段

作者:互联网

select * from 表名 where json字段名 ->> '$.json下的key值'

如果遇到json 嵌套的情况

select * from 表名 where json字段名 ->> '$.json下的key值.key值'以此类推。

(仅仅支持mysql5.7版本及以上)

 

id message_content 
1 {"reason": "未匹配任何规则", "applyId": "677ccd673a774283b10481c5c3104946", "auditConsequence": "0"}
2 {"reason": "未匹配任何规则", "applyId": "677ccd673a774283b10481c5c3104945", "auditConsequence": "0"}
3 {"reason": "未匹配任何规则", "applyId": "e39b453b9ae04e4980caba9099fbc551", "auditConsequence": "1"}

SELECT
message_content ->> '$.reason'
FROM
表名
WHERE
message_content ->> '$.auditConsequence' = '-1'

标签:auditConsequence,表名,reason,content,json,key,mysql,解析
来源: https://www.cnblogs.com/fnlingnzb-learner/p/15981501.html