mysql查找json格式列的指定字段值

SELECT json_extract(字段名,'$.json结构') FROM 表名;
如果json里有双引号,那这样取出来的数据也带双引号,要去掉就使用REPLACE函数

例如t_submit_answer表的SUBMIT_DATA字段值为:{"agentServiceId":"566a9511c7c544a6b8f58aa8499251e4","bustypeId":"9184ff0f-2a7d-4bcf-93c0-6aea94fa2bc1","callResult":"16","customerPhone":"013797014335","dataId":"ec676857-b684-4e28-b494-26b07c9f212c","jobId":"10.27.4.191_767c86f2-0582-489d-818c-36c6ea4f715a","qnaireId":"4cea5a6b-c190-43fb-8f5b-5f0e93d69620","taskId":"10.253.108.7_102fe254-d807-4d23-a1b5-90e9f3197295","visitMistake":"0"}

使用sql查询:

select REPLACE(json_extract(SUBMIT_DATA,'$.callResult'),'"','') as callResult from t_submit_answer order by CREATE_DATE;

得到结果为:16

注意:只有MySQL5.7及以上版本才支持json数据的操作

posted @ 2019-06-10 18:33  David~Chen  阅读(7484)  评论(0编辑  收藏  举报