我在下面的下一栏中使用自我查询需要经理姓名。有人可以帮忙吗?
eid ename ecity esal dno managerid
1001 Amit Kumar Delhi 20000 101 1005
1002 Amit Kumar Delhi 20000 101 1005
1003 Rahul Awasthi Delhi 20000 101 NULL
1004 Manish Singh Delhi 30000 101 1003
1005 Neetu Kumari Jasola 50000 102 NULL
1006 Jiya Bharti Jasola 60000 102 1005
1007 Priya Bharti Jasola 50000 102 1003
1008 Sulekha amritsar 25000 102 1005
1009 Sunil Kumar amritsar 39000 103 1003
1010 Satish amritsar 45000 103 1003
1011 Sunaina amritsar 49000 104 1003
1012 Arun kalkaji 100000 104 1005
1013 Rupa kalkaji 70000 104 NULL
1014 Ravi kalkaji 65000 105 NULL
1015 Nanch Srivastata delhi 55000 105 NULL
1016 Rahul Kalkaji 30000 NULL NULL
1017 Sunil Kalkaji 35000 NULL NULL
答案 0 :(得分:1)
您需要使用self join
select e.*,m.ename as ManagerName
from yourtable e
left join yourtable m on e.managerid = m.eid