SQL> select * from col_row_test;
NAM VAL1 VAL2 VAL3
--- ---------- ---------- ----------
a 1 2 3
b 1 2 3
c 1 2 3
d 1 2 3
结果
A B C D
---------- ---------- ---------- ----------
1 1 1 1
2 2 2 2
3 3 3 3
select max(a) a, max(b) b, max(c) c, max(d) d
from (select decode(nam, 'a', val1, '') a,
decode(nam, 'b', val1, '') b,
decode(nam, 'c', val1, '') c,
decode(nam, 'd', val1, '') d
from col_row_test)
union
select max(a), max(b), max(c), max(d) d
from (select decode(nam, 'a', val2, '') a,
decode(nam, 'b', val2, '') b,
decode(nam, 'c', val2, '') c,
decode(nam, 'd', val2, '') d
from col_row_test)
union
select max(a), max(b), max(c), max(d) d
from (select decode(nam, 'a', val3, '') a,
decode(nam, 'b', val3, '') b,
decode(nam, 'c', val3, '') c,
decode(nam, 'd', val3, '') d
from col_row_test)
阅读(1276) | 评论(0) | 转发(0) |