SQL如何将多行值合并

type  value
a      0
b      1
c      2
d      3
a      2
a      3
d      1
b      0
c      0
得到结果:
type value
a    0,2,3
b    1,0
c    2,0
d    3,1


select [type],
    stuff((select ','+ltrim(value) from tb
           where [type]=[type] for xml path('')),1,1,'') [value]
from tb
group by [type];

  



posted @ 2012-04-27 15:12  小锋神  阅读(399)  评论(0)    收藏  举报