mysql 字符串轉多行數據


數據存儲為 

 

 

 實現效果

 

 

 sql:

SELECT
    a.id,
    a.code,
    SUBSTRING_INDEX( SUBSTRING_INDEX( a.monitor_content, ',', b.id + 1 ), ',',- 1 ) AS ids 
FROM
    process_monitoring AS a
    JOIN process_monitor_content AS b ON b.id < ( length( a.monitor_content ) - length( REPLACE ( a.monitor_content, ',', '' ) ) + 1 )
        where a.code ='4203376628674604072';
View Code

process_monitor_content 表為自增序號表

格式ID 自增大於需要分組的字段就可以

 

參考

https://www.cnblogs.com/JMrLi/p/11320273.html

 


免責聲明!

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



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