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

求一条行转列 sql
结构是:

   表1

 A1  A2  A3
 1   2   3

我要变成

A1
1
2
3

菜鸟求助
行转列 sql

------解决方案--------------------
select A1 from 表
union all
select A2 from 表
union all
select A3 from 表
------解决方案--------------------

create table 表1
(A1 int, A2 int, A3 int)

insert into 表1
 select 1, 2, 3


select right(c,1) 'A1'
 from 表1 a
 unpivot(v for c in([A1],[A2],[A3])) p

/*
A1
----
1
2
3

(3 row(s) affected)
*/