mysql中如何在json数组中查询复合条件的json对象,
目前好实现的是转换临时表,在临时表中加where条件做判断。
select '[{"k": "1", "v": "https://www.bilibili.com/video/BV1dU4y147t8?from=search&seid=17686981769015229460&spm_id_from=333.337.0.0c", "desc": "提升排名视频课程"}, {"k": "1", "v": "https://www.bilibili.com/video/BV1xq4y1G7Mj?from=search&seid=272572936245601262&spm_id_from=333.337.0.0", "desc": "提升排名视频课程"}, {"k": "2", "v": "https://www.bilibili.com/video/BV1Sq4y1C7Jc?from=search&seid=272572936245601262&spm_id_from=333.337.0.0", "desc": "xxxx视频课程"}, {"k": "2", "v": "https://www.bilibili.com/video/BV1Ws411P7Nu?from=search&seid=272572936245601262&spm_id_from=333.337.0.0", "desc": "xxxx视频课程"}]' into @aa;
SELECT @aa;
select
*
from
json_table(@aa,'$[*]'
columns (k varchar(500) path '$.k',
`v` varchar(500) path '$.v',
`desc` varchar(500) path '$.desc'
)) as tt
where tt.k = 1
mysql官网链接:
MySQL :: MySQL 8.0 Reference Manual :: 12.18.6 JSON Table Functions