[英]SQL join columns of table with row of another table
I have a table with columns as Manager, TL, Architect etc which are populated with their emp_ids.我有一个表,其中包含 Manager、TL、Architect 等列,其中填充了它们的 emp_id。
Group Manager TL Architect
1 256 455 339
Another employee master table.另一个员工主表。
Emp_id Name Address
256 Rick Bombay
455 Dennis Madras
339 Harry Denver
How do I join these two tables to get Manager, TL and Architect details with group, name, address emp_id etc.如何加入这两个表以获取包含组、名称、地址 emp_id 等的 Manager、TL 和 Architect 详细信息。
I know that the table design is poor but I have no control on it.我知道桌子设计很差,但我无法控制它。 They are legacy tables and I have to work with them.它们是遗留表,我必须使用它们。
SELECT
g.GroupId
,mgr.Name AS Manager
,tl.Name AS TL
,arc.Name AS Architect
FROM Groups g
LEFT JOIN Employee mgr ON mgr.EmpId = g.ManagerId
LEFT JOIN Employee tl ON tl.EmpId = g.TlId
LEFT JOIN Employee arc ON ar.EmpId = g.ArchitectId
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.