SQL字符串分组聚合(分组后的数据查询后用逗号隔开)

时间:2015-01-04 16:55:52   收藏:0   阅读:633
create table tb(id int, value varchar(10))
insert into tb values(1, aa)
insert into tb values(1, bb)
insert into tb values(2, aaa)
insert into tb values(2, bbb)
insert into tb values(2, ccc)
go

select id, [value] = stuff((select , + [value] from tb t where id = tb.id for XML path(‘‘)) , 1 , 1 , ‘‘)
from tb
group by id

 

原文:http://www.cnblogs.com/shenyixin/p/4201291.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!