Mysql根据指定指定字符拆分某个字段,分割成多条记录(去重复)

1.如图

2.sql

SELECT DISTINCT
	substring_index( substring_index( a.device_id, ',', b.help_topic_id + 1 ), ',',- 1 ) NAME 
FROM
	tb_tabrecord a
	JOIN mysql.help_topic b ON b.help_topic_id < ( length( a.device_id ) - length( REPLACE ( a.device_id, ',', '' ) ) + 1 ) 
WHERE
	a.tt_id =1

substring_index() -----------------mysql  拆分函数

 mysql.help_topic  ----------------mysql 默认自增序列表

DISTINCT---------------------------mysql 去重复函数

查询结果

注意:如果要求拆分成多行必选要关联mysql自增表格

猜你喜欢

转载自blog.csdn.net/c_molione/article/details/82968554
今日推荐