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

2021/9/22 19:11:44

本文主要是介绍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

 



这篇关于MySQL逗号分割字段的拆分与合并的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程