1

我有3个postgresql表如下

雇员

emp_name | emp_id | user_name | psw | etc

工作

Work_id |work_type| Project_manger_id(employee) | Architect_id (emp) | tech_lead_id | dept_id

部门

dept_id | dept_name 

现在我想要的是一张这样的桌子

work_type | project_manager (name)  | architect (name) | tech_lead (name ) | dept (name )

简单地说,我想要的是获取工作表,但用名称替换 id

4

1 回答 1

3

试试这个

Select WT.Work_Type,PM.emp_name As ProjectManager,AR.emp_name AS Arhitect,TL.emp_name As  TechLead,Dept.Dept_name As Department From
Work 
INNER JOIN employees AS PM ON (Wt.Project_manger_id=PM.emp_id)
INNER JOIN employees AS AR ON (Wt.Architect_id=AR.emp_id)
INNER JOIN employees AS TL ON (Wt.tech_lead_id=TL.emp_id)
INNER JOIN Dept As Dept ON (Wt.dept_id=Dept.dept_id)
于 2012-05-28T05:06:23.190 回答