情景:
T1
主键 idstr
A 1,4,2,5
B 2,4,6,5,3
C 3,11,4,5,6
当
idstr=1,4 结果 A
idstr=6,5,3 结果 B,C
结果:
select a.id from (
select a.ID,substring_index(substring_index(a.idstr,',',b.help_topic_id+1),',',-1) as idstra
from
report_test a
join
mysql.help_topic b
on b.help_topic_id < (length(a.idstr) - length(replace(a.idstr,',',''))+1)
order by a.ID) a where instr(a.idstra,'1,4') group by a.id having count(1)>(length('1,4') - length(replace('1,4',',','')))