我正在尝试从 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 ;
给出: