mysql原生sql處理,按逗號拆分列為多行


舉例:

id value
1 1,2,3,4
2 2,3,4,5,6

拆分成:

 

id value
1 1
2 2
3 3
4 4
5 5
6 6
select distinct substring_index(substring_index(a.value,',',b.help_topic_id+1),',',-1)   
from table a  join  mysql.help_topic b  on b.help_topic_id < (length(a.value) - length(replace(a.value,',',''))+1)

distinct:去重復操作

a.value:表別名.需要拆分的字段名

table a:表名 別名

help_topic:自增長表


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM