答案 0 :(得分:1)
这不是关系结构,因为行中的列实际上并不相互关联。因此,通常最好在应用程序级别完成这种类型的转换。
也就是说,您可以在Oracle中执行此操作。一种方法是条件聚合:
select col1,
max(case when col3 = 'CAT1' then col2 end) as cat1,
max(case when col3 = 'CAT2' then col2 end) as cat2
from (select t.*, row_number() over (partition by col1, col3 order by col2) as seqnum
from t
) t
group by col1, seqnum
order by col1, seqnum;
答案 1 :(得分:1)
您可以使用PIVOT:
select col1, cat1, cat2
from (
select t.*, row_number() over (partition by col3 order by col2) as rn
from t
)
pivot (min(col2) for (col3) in ('CAT1' as "CAT1", 'CAT2' as "CAT2"))
order by rn;