数据库
首页 > 数据库> > MySQL逗号分割字段的拆分与合并

MySQL逗号分割字段的拆分与合并

作者:互联网

update
	test aa,
	(
	select
		c.id,
		GROUP_CONCAT(c.prov_code) prov_code,
		GROUP_CONCAT(ifnull(p.name, c.prov_code)) prov_name
	from
		(
			SELECT
				a.id,
				SUBSTRING_INDEX(SUBSTRING_INDEX(a.i_prov_codes, ',', b.help_topic_id + 1), ',',-1) prov_code
			FROM
				(
				SELECT
					b.id,
					GROUP_CONCAT(REPLACE(prov_codes, '/', ',')) AS i_prov_codes
				FROM
					test b
				group by
					id) a
			JOIN mysql.help_topic b
				ON b.help_topic_id < (LENGTH(a.i_prov_codes) - LENGTH(REPLACE(a.i_prov_codes, ',', '')) + 1)
		) c
			left join test_province p
				on p.province_code = c.prov_code
	group by
		c.id
) d
set
	aa.cover_prov_display_name = d.prov_name
where
	aa.prov_codes = d.prov_code
	and aa.id = d.id

 

标签:aa,code,name,prov,逗号,字段,codes,MySQL,id
来源: https://blog.csdn.net/chyercn/article/details/120413211