Last active
August 29, 2015 13:56
-
-
Save zelark/9132652 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with tab | |
as (select 'aa' as p1, 'bb' as p2 from dual union all | |
select 'cc' as p1, 'dd' as p2 from dual union all | |
select 'ee' as p1, 'ff' as p2 from dual union all | |
select 'gg' as p1, 'hh' as p2 from dual) | |
select max(case when rownum = 1 then p1 || p2 end) as r1, | |
max(case when rownum = 2 then p1 || p2 end) as r2, | |
max(case when rownum = 3 then p1 || p2 end) as r3, | |
max(case when rownum = 4 then p1 || p2 end) as r4 | |
from tab; | |
-- or with "pivot" | |
with tab | |
as (select 1 as id, 'aa' as p1, 'bb' as p2 from dual union all | |
select 2 as id, 'cc' as p1, 'dd' as p2 from dual union all | |
select 3 as id, 'ee' as p1, 'ff' as p2 from dual union all | |
select 4 as id, 'gg' as p1, 'hh' as p2 from dual) | |
select * | |
from (select id, p1, p2 from tab) | |
pivot (max(p1 || p2) for id in (1 as r1, 2 as r2, 3 as r3, 4 as r4)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment