select max(decode(s,1,x,null) a,
max(decode(s,2,x,null) b,
max(decode(s,3,x,null) c,
max(decode(s,4,x,null) d from (
select x,n,row_number()over(partition by n order by n) s from
( select 列1 x,1 n from 表 union all select 列2 x,2 from 表 union all
select 列3 x,3 from 表 union all select 列4 x,4 from 表 )
)
group by
max(decode(s,2,x,null) b,
max(decode(s,3,x,null) c,
max(decode(s,4,x,null) d from (
select x,n,row_number()over(partition by n order by n) s from
( select 列1 x,1 n from 表 union all select 列2 x,2 from 表 union all
select 列3 x,3 from 表 union all select 列4 x,4 from 表 )
)
group by
max(decode(s,2,x,null) b,
max(decode(s,3,x,null) c,
max(decode(s,4,x,null) d from (
select x,n,row_number()over(partition by n order by n) s from
( select 列1 x,1 n from 表 union all select 列2 x,2 from 表 union all
select 列3 x,3 from 表 union all select 列4 x,4 from 表 )
)
group by n;
如果是为了能在别的地方用, 那就生成一个表,
以上方法与源表的列数无关。
如果源表的列数是不固定的,用一条SQL, 好象很难