mysql字符串分割操作
Posted Enjoy Life
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql字符串分割操作相关的知识,希望对你有一定的参考价值。
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字符串分割操作的主要内容,如果未能解决你的问题,请参考以下文章