http://xiangai.taobao.com
http://shop148612228.taobao.com

sql server 怎么实现mysql中group_concat,列转行,列用分隔符拼接字符串

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 * from tb;

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

drop table tb

posted @ 2016-02-01 18:22  万事俱备就差个程序员  阅读(11819)  评论(0编辑  收藏  举报

http://xiangai.taobao.com
http://shop148612228.taobao.com
如果您觉得对您有帮助.领个红包吧.谢谢.
支付宝红包
微信打赏 支付宝打赏