您只需要加入
Select proj_id,
t1.name + ' ' + t1.surname tester1,
t2.name + ' ' + t2.surname tester2,
t3.name + ' ' + t3.surname tester3
From Project p
Left Join Emp t1 On t1.emp_id = p.Tester_1
Left Join Emp t2 On t2.emp_id = p.Tester_2
Left Join Emp t2 On t3.emp_id = p.Tester_3
作爲視圖...
Create View ProjectWithTesters
As
Select proj_id,
t1.name + ' ' + t1.surname tester1,
t2.name + ' ' + t2.surname tester2,
t3.name + ' ' + t3.surname tester3
From Project p
Left Join Emp t1 On t1.emp_id = p.Tester_1
Left Join Emp t2 On t2.emp_id = p.Tester_2
Left Join Emp t2 On t3.emp_id = p.Tester_3
注:正如其他人所提到的,你的數據庫的設計違反了第一範式「不應該有重複的組」,這意味着表不應該包含多個表示某個屬性的多個實例的列(如您的tester_1,tester_2,tester_3)。看看這個鏈接:database normalization瞭解更多信息。
關於什麼的任何想法?這裏沒有真正的問題。你有什麼麻煩? – Jimmeh 2009-12-01 14:43:16
EMP-PROJECT關係表或FOREIGN鍵在哪裏? – 2009-12-01 14:44:51