如何获得姓名和经理姓名

+----+-----------+---------+
| id | name      | manager |
+----+-----------+---------+
|  1 | bhupendra |       0 |
|  2 | shyam     |       1 |
|  3 | ram       |       1 |
|  4 | geeta     |       2 |
|  5 | sita      |       1 |
+----+-----------+---------+


我需要像这样的结果

+-----------+-----------+
| name      | manager   |
+-----------+-----------+
| bhupendra |           |
| shyam     | bhupendra |
| ram       | bhupendra |
| geeta     | shyam     |
| sita      | bhupendra |
+-----------+-----------+

最佳答案

您应该使用别名两次使用同一张表

select a.name, b.name as manager
from my_table a
left join  my_table b on a.manager  = b.id

08-06 22:03