表名:員工
sr | name | head_id
--------------------
1 | rahul | 2
2 | amit | 0
3 | john | 1
期望輸出:
sr | name | head_id | head_name
---------------------------------
1 | rahul | 2 | amit
2 | amit | 0 |
3 | john | 1 | rahul
我想要一個查詢,我可以根據他們的 head_id 獲取 head_name
您可以使用join
來獲得所需的輸出。
select e.sr,e.name,e.head_id,e1.name
from employee e
join employee e1 on e.head_id = e1.sr
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句