当前位置:Gxlcms > 数据库问题 > Mysql中字段分割字符串( 一行转多行 )

Mysql中字段分割字符串( 一行转多行 )

时间:2021-07-01 10:21:17 帮助过:4人阅读

技术图片

需要的结果:

技术图片

sql实现

SELECT
    a.id,
    a.username,
    SUBSTRING_INDEX( SUBSTRING_INDEX( a.operid, ;, b.help_topic_id + 1 ), ;,- 1 ) AS ids 
FROM
    `t_customers` AS a
    JOIN mysql.help_topic AS b ON b.help_topic_id < ( length( a.operid ) - length( REPLACE ( a.operid, ;, ‘‘ ) ) + 1 ); 

如mysql.help_topic: help_topic_id 共有504个数值 它们是mysql内部的连续数列表,连续数列的最大值一定要大于符合分割的值的个数。

------------------------------------------------------------------------------------------------------------------------------------

mysql 字段截取函数:

1、left(字段名,index) 从左边开始第index开始截取

2、right(字段名,index)从右边开始第index开始截取

3、substring(字段名,index)当index>0从左边开始截取直到结束  当index<0从右边开始截取直到结束  当index=0返回空

4、substring(字段名,index,len)从index开始,截取len长度

5、substring_index(字段名,str,count),str是截取的字段 count是从哪里开始截取(0从左边第0个开始,-1从右边第一个开始)

Mysql中字段分割字符串( 一行转多行 )

标签:rom   from   mysql   div   _id   长度   color   style   png   

人气教程排行