create table incre_table
(
AutoIncreID int
);
insert into incre_table
values (1);
insert into incre_table
values (2);
insert into incre_table
values (3);
select group_concat(t2.name)
from (select a.ID, substring_index(substring_index(a.tags, ',', b.AutoIncreID), ',', -1) as tag
from code_task a
join
incre_table b
on b.AutoIncreID <= (length(a.tags) - length(replace(a.tags, ',', '')) + 1)) as t1
join tag_table t2
on t1.tag = t2.id
group by t1.id;
如果有 8 以上的版本,可以尝试下面的 sql(未验证)
with a as (select * from code_task)
select group_concat(name)
from (select name, '1' as tmp from tag_table b where find_in_set(b.id, a.tags)) as nt
group by tmp;
mysql 下面实现非常麻烦,我的版本是 5.7.30
这个应该在任何版本都能实现(5.7.30 已验证),incre_table 的记录数需要大于或者等于 tags 按 , 分割的长度,并且顺序不能跳跃
如果有 8 以上的版本,可以尝试下面的 sql(未验证)