mysql 查詢json相關

mysql數據庫數據如圖,存放的是json字符串

現在需要進行模糊查詢,查詢productId中有76的

select bace.name,bace.target->'$.productId'
from bill_coupon as bace
where FIND_IN_SET('76', json_unquote(json_extract(bace.target,'$.productId'))); 

1、json_extract 獲取json中指定的值

獲取指定json字符串中指定的屬性值,以下三種等同:

json_extract(target,'$.productId')

target->'$.productId'

target->>'$.productId' //可以有兩個尖括號

2、json_unquote 去掉查詢結果中首尾的雙引號

去除雙引號後,纔會是 find_in_set('76',"76,77,79")
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章