日期:2014-05-17  浏览次数:20653 次

sql语句Orz

组合     明细
0010 A:D1|32
0002 d:d|2
0003 A:A|1
0001 A:D|2
0001 A:D|23
0001 A:B1|2
8    2a:s|2
9    2a:s|2

我要查出这样的数据出来
0010  A:D1|32
0002  d:d|2
0003  A:A|1
0001  A:D|2&A:D|23&A:B1|2
8     2a:s|2
9     2a:s|2
在线等 不知道我的意思表达清楚了没

------解决方案--------------------
select 组合,stuff((select '&'+明细 from tb where a.组合=组合 for xml path(''))1,1,'')明细
from tb as a group by 组合