转载 :https://www.cnblogs.com/DONET-LC/p/14510440.html
--多行数据分组后合并某个字段 declare @tabs table(tId int,name nvarchar(10)) insert @tabs values (1,'linda'), (1,'salar'), (2,'mom'), (2,'cc') select tId, stuff( (select '、'+name from @tabs where tId = t.tId for xml path('')),1,1,'' ) staffIds from @tabs t group by tId
Mysq可以使用另一个方法
select DepartId,group_concat(UserName separator '_') from m_users group by m_users.DepartId;