inverse row to column

瘦欲@ 提交于 2019-11-29 12:50:32

Please try UnPIVOT:

SELECT substr(kind,2,1) AS kind,"value" FROM 
(    
    SELECT
        5 AS l0,
        2 AS l1,
        3 AS l2,
        4 AS l3
    FROM dual
)temp unpivot include NULLS ("value" FOR kind IN (l0, l1 , l2, l3));

Inversely:

 SELECT *   
 FROM 
 (
      SELECT Kind,
             max(Value) Value
      FROM table 
      GROUP BY Kind
 ) PIVOT ( max(Value) FOR Kind IN (L0, L1, L2, L3) );

Assuming that you actually have a table to query from.

select i - 1 kind,
case when i = 1 then L0 when i = 2 then L1 when i = 3 then L2 when i = 4 then L3 end as value from your_table, (select level as i from dual connect by level <= 4)
This does a Carteasan Product of your table and the "inline view." The inline view will output four rows, 1 through 4.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!