sqlserver列转行
发布时间: 2023-03-01 21:31:08
A. sql 列转行
CREATE TABLE T1(A NUMBER,
b NUMBER,
c NUMBER,
d NUMBER,
e NUMBER);
insert into t1 values(1,2,3,4,5);
select * from t1;
select decode(A,1,'A',null) KEY ,decode(A,1,1,null) VALUE
from t1
union all
select decode(B,2,'B',null),decode(B,2,2,null)
from t1
union all
select decode(C,3,'C',null),decode(C,3,3,null)
from t1
union all
select decode(D,4,'D',null),decode(D,4,4,null)
from t1
union all
select decode(E,5,'E',null),decode(E,5,5,null)
from t1;
热点内容