如何将列和行转换/转换为单列oracle sql?

时间:2017-07-03 06:42:11

标签: sql oracle oracle11g

image1

image2

image3

如何将一系列数据转换或转置到单个列中,如上所示?数据中的值可能不明确,但输出应仅包含唯一值。

2 个答案:

答案 0 :(得分:0)

(在评论中提供更多信息后更新)

如果您的初始数据来自查询,则可以使用common table expression执行此操作:

with query_results (a,b,c) as ( 
   ... your original query that you have not shown us goes here ...
)
select a
from query_results
union 
select b 
from query_results
union
select c
from query_results
order by 1

UNION运算符将从输出

中删除重复项

答案 1 :(得分:0)

您可以使用UNPIVOT

SELECT value
FROM   your_table
UNPIVOT ( value FOR type IN ( a, b, c ) );
相关问题