-1

My input table looks like this

Employee Manager
rahul aria
aria priya
priya sheela
vasant reema
reema carol
guha reeye

This is the output I want

Employee Manager 1 Manager 2 Manager 3
rahul aria priya sheela
vasant reema carol
guha reeya

How can I achieve this? I tried until I can make it to the only manager, but not sure how to build columns as manager-employee relationship goes on

Yash
  • 105
  • 10

1 Answers1

0

You can use SQL hierarchy query to retrieve :

    with tabletest as 
(
select 
'rahul' employee , 'aria' as manager from dual
union 
select 
'aria' as employee, 'priya' as manager from dual
union 
select
'priya' as employee, 'sheela' as manager from dual
)

select level, a.employee, Sys_Connect_By_Path(a.manager,'/') as path from tabletest a
connect by prior a.employee = a.manager;

enter image description here

AN Đỗ
  • 29
  • 4
  • 1
    The tag is MySQL, connect is Oracle. PS [Why should I not upload images of code/data/errors when asking a question?](https://meta.stackoverflow.com/q/285551/3404097) [Why are images of text, code and mathematical expressions discouraged?](https://meta.stackexchange.com/q/320052/266284) [mre] [answer] [Help] – philipxy Apr 12 '23 at 09:09