现在的位置: 首页 > 综合 > 正文

SQL 行列转置

2014年01月23日 ⁄ 综合 ⁄ 共 1917字 ⁄ 字号 评论关闭

 

 我学会了第二种方法:

sql2005中的方法
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

drop table tb

本文来自: IT知道网(http://www.itwis.com) 详细出处参考:http://www.itwis.com/html/database/sqlserver/20090302/3458.html

抱歉!评论已关闭.