我正在嘗試從 mysql 列中的巢狀 json 中搜尋 userId 值 22
我的json是
'{ "data": [ {"calendarId":"11","userId": "12"}, {"calendarId":"21","userId": "22"} ] }'
我嘗試了以下語法:
1. where JSON_EXTRACT(column_field,'$.userId') = 22 2. where JSON_EXTRACT( column_field, '$.data[*].userId' ) = 22
P粉5548420912023-09-07 09:42:13
這個:
select json_extract('{ "data": [ {"calendarId":"11","userId": "12"}, {"calendarId":"21","userId": "22"} ] }','$[0].data[*].userId');
給出:[“12”,“22”]
#還有這個:
select * from json_table(json_extract('{"data": [{"calendarId":"11","userId": "12"},{"calendarId":"21","userId": "22"}]}', '$[0].data[*].userId'), '$[*]' columns (value int path "$")) x ;
給出: