SQL select命令

时间:2011-11-13 01:29:15

标签: sql sql-server sql-server-2005

在sql中我有一个这样的表:


empno   |  empname  |  supervisors
------      -------   -------------
1            AAA          NULL           
2            BBBBB          1            
3            CCCCC          2
4            DDDD           3 

现在我想要像这样的输出


empno   |  empname  |  supervisors
------      -------   -------------
1            AAA          NULL           (he is the boss, he don't have supervisors)
2            BBBBB        AAA            (the number is replaced by empname)
3            CCCCC        BBBBB
4            DDDD         CCCCC 

请帮助我!

1 个答案:

答案 0 :(得分:6)

SELECT e.empno, e.empName, s.empname
FROM eployee AS e
LEFT JOIN eployee AS s ON e.supervisors = s.empno