MySQL逗号分割字段的列转行

#SQL
select a.ID,substring_index(substring_index(a.mSize,',',b.help_topic_id+1),',',-1) 
from 
tbl_name a
join
mysql.help_topic b
on b.help_topic_id < (length(a.mSize) - length(replace(a.mSize,',',''))+1)
order by a.ID;

 

 

 

 

 

SELECT
    l.code '课code',
    r.`name` '资源名称',
    r.path
FROM `p_course` c
LEFT JOIN `p_course_sub_relation` csr ON c.id = csr.`course_id`
LEFT JOIN `p_lesson` l ON csr.`sub_id` = l.`id`
LEFT JOIN `p_lesson_ware_relation` lwr ON l.id = lwr.`lesson_id`
LEFT JOIN `p_courseware` cw ON lwr.`ware_id` = cw.id
JOIN mysql.help_topic b ON b.help_topic_id < (LENGTH(cw.`resource_list`) - LENGTH(REPLACE(cw.`resource_list`,',',''))+1)
LEFT JOIN `r_resource` r ON  r.`id` = SUBSTRING_INDEX(SUBSTRING_INDEX(cw.`resource_list`,',',b.help_topic_id+1),',',-1)

WHERE c.code IN ('C-04-42-01','C-04-41-01')
ORDER BY c.code,l.code,cw.code

你可能感兴趣的:(mysql)