-3

I have a table like the following:

enter image description here

I want to extract data like below. Please how can I do that?

enter image description here

Thanks !

Nicolas
  • 83
  • 1
  • 7

1 Answers1

1

You can use row_number() and group by:

select max(case when hierarchy = 'A' then l_name end) as A,
       max(case when hierarchy = 'B' then l_name end) as B,
       max(case when hierarchy = 'C' then l_name end) as C
from (select t.*,
             row_number() over (partition by hierarchy order by l_name) as seqnum
      from t
     ) t
group by seqnum;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786