0

我有五张看起来像这样的桌子

BugHistory             
--------------------   
BugHistoryID
BugId
EmployeeId                  

Bugs
--------------------
BugID
Description
ProjectID
PriorityID

Employee                    
-------------------      
EmployeeId
EmployeeName   

Projects                
-------------------     
ProjectID
ProjectName    

Priority
-------------------
PriorityID
PriorityName

我想从所有表中检索数据,制作BugHistory主表。

我需要[Description],[ProjectName],[PriorityName]剩下的四个表中EmployeeID的关键在哪里。

应根据 BugHistory 表中的 EmployeeID 检索数据;我将根据登录名获取 EmployeeID。谁能帮我写这个查询?

4

1 回答 1

4

这应该可以满足您的需求。

SELECT b.Description
    , pj.ProjectName
    , pr.PriorityName
FROM BugHistory bh
INNER JOIN Employee e
     ON bh.EmployeeId = e.EmployeeId
INNER JOIN Bugs b
     ON bh.BugId = b.BugId
INNER JOIN Project pj
    ON b.ProjectId = pj.ProjectId
INNER JOIN Priority pr
    ON b.PriorityId = pr.PriorityId
于 2012-07-23T13:58:39.903 回答