1111 aa
1111 bb
2222 cc
2222 dd
转化为
1111 aa,bb
2222 cc,dd
------解决方案--------------------
这不是行转列,这是字符串的拼接。
- SQL code
select col1, stuff((select ','+col2 from tb where col1 = t.col1 for xml path('')),1,1,'') as col2from tb tgroup by col1--sql2005 try !
select col1, stuff((select ','+col2 from tb where col1 = t.col1 for xml path('')),1,1,'') as col2from tb tgroup by col1--sql2005 try !