如何从同一个表中获取Refernce ID的值?

时间:2016-12-20 14:44:26

标签: mysql

我有一个Employee表,其中包含Employee Number,report ID,Emp.Name等。我将Emp.No存储在Reporting ID列中。现在我想显示员工姓名而不是他们特定员工的报告ID。我尝试了一些东西,但效果不好。

这是我的代码

SELECT  Distinct
hma.First_Name as Reporting1,
hmaa.First_Name as Reporting2,
hmaaa.First_Name as Reporting3,
hmaaaa.First_Name as Reviewer
from  abc hm
left join abc hma on hm.Employee_Number=hma.Reporting1
left join abc hmaa on hma.Employee_Number=hmaa.Reporting2
left join abc hmaaa on hmaa.Employee_Number=hmaaa.Reporting3
left join abc hmaaaa on hmaaa.Employee_Number=hmaaaa.Reviewer
where hmaaa.Employee_Number=97876757
Group by Reporting1,Reporting2,Reporting3,Reviewer;

0 个答案:

没有答案