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
原始數據:sql
ID Name A S A M A L B S B M B Lxml
結果數據:blog
ID NameA S,M,LB S,M,Lclass