请教Mysql 多列合并的SQL编写

MySql 码拜 8年前 (2016-02-06) 1303次浏览
请教Mysql 多列合并的SQL编写
有没有人碰到过这种奇葩的需求,将多列合并,且重复的字符串要去掉的,求高手指点
解决方案

40

select id,group_concat(name)
from (
	select id,name from table1
	union
	select id,zy_name from table1
	union
	select id,maj_name from table1
	union
	select id,SUBSTRING_INDEX(maj_zy_name,",",1) from table1
	union
	select id,SUBSTRING_INDEX(maj_zy_name,",",-1) from table1
) t
group by id

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明请教Mysql 多列合并的SQL编写
喜欢 (0)
[1034331897@qq.com]
分享 (0)