一列包含ID,对于相同的ID,它们是不同的名称。
ID Name
1 Amrutha
1 Ankith
1 Lalitha
1 Kavitha
2 Nithin
2 Raghu
2 Pramodh
结果应为
1 Amrutha,Ankitha,Lalitha,Kavitha
2 Nithin,Raghu,Pramodh
请帮我这样做。当我使用Group by子句时,我收到了错误。
答案 0 :(得分:1)
select
id,
stuff(
( Select ','+t.name from t where t.id = b.id for xml path ('') ),
1, 1, ''
) as dept
from t b
group by id