if not object_id('tb') is null drop table tb Go Create table tb([字段1] nvarchar(1),[字段2] nvarchar(1)) Insert tb select N'a',N'c' union all select N'b',N'c' Go Select [字段1]=stuff((select ','+[字段1] from tb where [字段2]=t.[字段2] for xml path('')),1,1,''), [字段2]from tb t group by [字段2]
drop table tb
Go
Create table tb([字段1] nvarchar(1),[字段2] nvarchar(1))
Insert tb
select N'a',N'c' union all
select N'b',N'c'
Go
Select [字段1]=stuff((select ','+[字段1]
from tb
where [字段2]=t.[字段2]
for xml path('')),1,1,''),
[字段2]from tb t
group by [字段2]