在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
请帮助我!
答案 0 :(得分:6)
SELECT e.empno, e.empName, s.empname
FROM eployee AS e
LEFT JOIN eployee AS s ON e.supervisors = s.empno