select ID,
Name =
(
stuff
(
(
select ',' +
Name from Table_1 where ID =
a.ID for xml path('')
),1,1,''
)
) from Table_1 a group by ID
原始数据:
ID Name
A S
A M
A L
B S
B M
B L
结果数据:
ID Name
A S,M,L
B S,M,L
2023-09-26 12:46:16
select ID,
Name =
(
stuff
(
(
select ',' +
Name from Table_1 where ID =
a.ID for xml path('')
),1,1,''
)
) from Table_1 a group by ID
原始数据:
ID Name
A S
A M
A L
B S
B M
B L
结果数据:
ID Name
A S,M,L
B S,M,L