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%"