I have following table with data
emp_no emp_name login HOD_code Level E43057 Ankita Barde 9:45 P00212 Direct E33995 Rakesh Sharma 8:15 P00212 Direct E31446 Amit Singh 10:45 P00212 Direct E44920 Shweta Salve 9:38 E33995 Indirect E39787 Anita Shenoy 9:15 E31446 Indirect E37731 Ramesh Shukla 9:10 E31446 Indirect E43455 Manish Shukla 11:01 E33995 Indirect E43130 Lubna Shaikh 9:39 E33995 Indirect
In the above table I have one HOD code (P00212) superior to all so employee which are mapped under P00212 are specified as direct employee in the LEVEL column and all others are indirect to P00212. But this indirect employees are mapped under Direct Employee
For eg: P00212 is HOD of Rakesh Sharma (E33995) and E33995 is HOD of 3 other employe i.e Shweta(E44920), E43455, E43130. So I want to write a query in such way that the output will look like the following
OUTPUT:
emp_no emp_name login HOD_NO Level E43057 Ankita Barde 9:45 P00212 Direct E33995 Rakesh Sharma 8:15 P00212 Direct E43455 Manish Shukla 11:01 E33995 Indirect E43130 Lubna Shaikh 9:39 E33995 Indirect E44920 Shweta Salve 9:38 E33995 Indirect E31446 Amit Singh 10:45 P00212 Direct E39787 Anita Shenoy 9:15 E31446 Indirect E37731 Ramesh Shukla 9:10 E31446 Indirect
How can I do this?
SQLFiddle Example