34.mysql拆分json示例

发布时间 2023-07-04 11:27:50作者: zhangdapangzi

create table json_test (id int ,f varchar(100));

insert into json_test values(1,'[{"name":"25岁及以下","value":1},{"name":"36-40岁","value":2},{"name":"31-35岁","value":3}]');


select
json_extract(f,concat("$[",ht.help_topic_id,"].name")) as name,
json_extract(f,concat("$[",ht.help_topic_id,"].value")) as value
from json_test jt
inner join
mysql.help_topic ht
ON ht.help_topic_id < JSON_LENGTH(jt.f)