SELECT ‘1,2,3,4,5,6,7,8‘ FROM dual; -- 列转行分割 SELECT DISTINCT SUBSTRING_INDEX(SUBSTRING_INDEX(a.path,‘,‘,b.help_topic_id + 1),‘,‘,-1) FROM (SELECT GROUP_CONCAT(REPLACE(path,‘/‘,‘,‘)) AS path FROM department b WHERE department_type = 1) a JOIN mysql.help_topic b ON b.help_topic_id < (LENGTH(a.path) - LENGTH(REPLACE(a.path,‘,‘,‘‘)) + 1); -- 测试 SELECT DISTINCT SUBSTRING_INDEX(SUBSTRING_INDEX(a.path,‘,‘,b.help_topic_id + 1),‘,‘,-1) as path FROM (SELECT ‘1,2,3,4,5,6,7,8‘ as path FROM dual) a JOIN mysql.help_topic b ON b.help_topic_id < (LENGTH(a.path) - LENGTH(REPLACE(a.path,‘,‘,‘‘)) + 1);
测试结果:
原文地址:https://www.cnblogs.com/wangwiz/p/9019472.html
时间: 2024-10-08 19:40:01