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;
熱點內容