value | num |
---|---|
1 | 1,2,3,4,1 |
此种结构 将 num 转为一列一列
SELECT DISTINCT
a.`value`,substring_index(substring_index( a.`num`, ',', b.help_topic_id + 1 ), ',',- 1 ) as result
FROM
test a
JOIN mysql.help_topic b ON b.help_topic_id < (
length( a.`num` ) - length(
REPLACE ( a.`num` , ',', '' ))+ 1);
变成
value | result |
---|---|
1 | 1 |
1 | 2 |
1 | 3 |
1 | 4 |
1 | 1 |
主要就是那个
JOIN mysql.help_topic b ON b.help_topic_id < (
length( a.`num` ) - length(
REPLACE ( a.`num` , ',', '' ))+ 1);