SQL语句中对json数据的查询

1.获取指定json字符串中指定的属性值,以下三种写法等价: 

json_extract(attributes_json,'$.DP')   //json_extract()方法获取json中指定的值,格式:json_extract(json_field,'$.DP')
 
attributes_json
->'$.DP' //attributes_json字段的值为一个json字符串,下面的语句都是获取attributes_json中的DP属性的值
attributes_json->>'$.DP'               //可以有两个尖括号
举例:

2.去掉查询结果中首尾的双引号:
json_unquote()
SELECT json_unquote(json_extract (tea.`teacher_class_type`,'$[0].Id')) FROM tb_teacher tea WHERE tea.`biz_id` = '00000000b162333ff'

还可以以下方式:

REPLACE去除结果中的双引号
SELECT REPLACE(tea.`teach_id` -> '$[0].id','"','') AS 'sch' FROM tb_teacher tea 

 3.SQL的json查询

举例:数据格式

 查询语句:

 JSON_CONTAINS(tea.`teacher_class_type`-> '$[*].id','"3643201711********0784504660"')

或者

tea.`teacher_class_type` LIKE "%36432017110********45046601%"
posted @ 2019-09-30 14:34  snoweveryday  阅读(27187)  评论(2编辑  收藏  举报