1. 程式人生 > >mysql字符串分割操作

mysql字符串分割操作

index length path topic _id spa info inf color

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);

測試結果:

技術分享圖片

mysql字符串分割操作