Patient_Detail
。Check_Out
Check_Out_ID,Illness_ID,Check_Out_Date。 Check_In
Check_In_ID,Illness_ID,Check_In_Date。 Illness
有 Illness_ID,Illness_Name。 illness_Name
表加入Check_out
。< / p>
USE PantienDatabase
SELECT Name,Check_in,Illness_name,Check_out_ID FROM Check_In AS CI
INNER JOIN Patient_Detail AS P
ON CI.Check_In_ID = P.Check_In_ID
INNER JOIN Illness AS I
ON I.IllnessID =CI.illness_ID
INNER JOIN
Check_Out AS CO
ON CO.Check_Out_ID = P.Check_out_ID
答案 0 :(得分:1)
您可以将同一个表连接两次,并为所选列使用别名:
SELECT Name, Check_in,
II.Illness_name AS Illness_name_in,
IO.Illness_name AS Illness_name_out,
Check_out_ID
FROM Check_In AS CI
INNER JOIN Patient_Detail AS P ON CI.Check_In_ID = P.Check_In_ID
INNER JOIN Illness AS II ON II.IllnessID = CI.illness_ID
INNER JOIN Check_Out AS CO ON CO.Check_Out_ID = P.Check_out_ID
INNER JOIN Illness AS IO ON IO.IllnessID = CO.illness_ID