程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SyBase數據庫 >> SyBase教程 >> unpivot轉多列並包含多個名稱

unpivot轉多列並包含多個名稱

編輯:SyBase教程

unpivot轉多列並包含多個名稱


CREATE TABLE  T5 (idnum NUMBER,f1 NUMBER(10,5),f2 NUMBER(10,5),f3 NUMBER(10,5),e1 NUMBER(10,5),e2 NUMBER(10,5),h1 NUMBER(10,5),h2 NUMBER(10,5));

INSERT INTO T5 (IDNUM,F1,F2,F3,E1,E2,H1,H2) VALUES (1,'10.2004','5.009','7.330','9.008','8.003','.99383','1.43243');
INSERT INTO T5 (IDNUM,F1,F2,F3,E1,E2,H1,H2) VALUES (2,'4.2004','6.009','9.330','4.7008','4.60333','1.993','3.3243');
INSERT INTO T5 (IDNUM,F1,F2,F3,E1,E2,H1,H2) VALUES (3,'10.2040','52.6009','67.330','9.5008','8.003','.99383','1.43243');
INSERT INTO T5 (IDNUM,F1,F2,F3,E1,E2,H1,H2) VALUES (4,'9.20704','45.009','17.330','29.008','5.003','3.9583','1.243');

COMMIT;

select *
from (select IDNUM,F1,F2,F3,E1,E2,H1,H2, null as E3,null as H3
        from T5)
UnPivot((F,E,H) for sk in ((F1,E1,H1) as 1, (F2,E2,H2) as 2, (F3,E3,H3) as 3))
order by IDNUM,SK;

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved