mysql将一行拆分成多行(字符串分割函数)
目前有表如下现在 需要将课程根据分号分割成多行-- 使用mysql库中的自增序列表SELECTt.id,t.NAME,substring_index(substring_index(t.curriculums,';',b.help_topic_id + 1),';',- 1) AS curriculumFROMtest tJOIN mysql.help_topic b ON b.help_topi
·
目前有表如下
现在 需要将课程根据分号分割成多行
-- 使用mysql库中的自增序列表
SELECT
t.id,
t.NAME,
substring_index(
substring_index(
t.curriculums,
';',
b.help_topic_id + 1
),
';',- 1
) AS curriculum
FROM
test t
JOIN mysql.help_topic b ON b.help_topic_id < (
length( t.curriculums ) - length( REPLACE ( t.curriculums, ';', '' ) ) + 1
)
运行结果
不推荐使用此种方式,应该坚持每个数据都是不可分割的原子数据,推荐建立关联表存储
更多推荐
所有评论(0)