+ -
当前位置:首页 → 问答吧 → oracle 行列转化

oracle 行列转化

时间:2011-12-02

来源:互联网

网上只有一种,我需要另外一种。比如 
表A
id n1,v1,n2,v2,n3,v3
1, 01,12,03,14,05,2
转成
id, N,V
 1, 01,12
 1, 03,14
 1, 05,2
转成后的结果不要id列也可以。

作者: jinyuttt   发布时间: 2011-12-02

SQL code
select ID,N1 as N,v1 as V from A
union all 
select ID,N2,v2 from A
union all 
select ID,N3,v3 from A

作者: roy_88   发布时间: 2011-12-02

我觉得在你知道你的表有多少个Nx和Vx的情况下,你可以使用土的方法union 起来

select id,n1 as n ,v1 as v from tb_name 
union all
select id,n2 as n ,v2 as v from tb_name
...
....

作者: BearFishShow   发布时间: 2011-12-02