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
解决方案 »
- 请教PL/SQL中类似MSSQLSERVER execute('select * from tables')的写法
- 请教:Io 异常: Software caused connection abort: socket write error ??
- 数据库用户权限
- svrmgrl登录报权限不足的问题!
- oracle备份(exp) 比较难的问题
- 关于ORA-01009: 缺少法定参数,谢谢?
- 大哥大姐帮帮忙:
- 高分求解——高手请进
- PL/SQL中的转意问题
- 急!!!高分求解!!!IMP-00016: 不支持要求的字符集转换(从类型850到852)问题!
- 数据库升级和移植的问题?
- 弱问题:关于COMMIT。
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, 好象很难