Skip to content

Instantly share code, notes, and snippets.

@zelark
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zelark/9132652 to your computer and use it in GitHub Desktop.
Save zelark/9132652 to your computer and use it in GitHub Desktop.
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