我在Oracle APEX工作。我正在通过以下四个表格Patient History Junction and Disease
制作报告,但无法制作报告。
我想要SELECT
来自患者表的Pat_Name,Pat_Age`
。
Treated_By,来自历史记录表的Sys_Date
和
疾病表中的Dis_Name
。Junction
之间有History and Disease
表。以下是上述方案的图表。
答案 0 :(得分:1)
您需要JOIN
每个表,类似于:
select p.pat_name,
p.pat_age,
h.treated_by,
h.sys_date,
d.dis_name
from patient p
inner join history h
on p.pat_id = h.pat_id
and p.app_id = h.app_id
left join junction j
on p.pat_id = j.pat_id
left join disease d
on j.dis_id = d.dis_id
如果您需要帮助学习加入语法,请查看这个有用的visual explanation of joins。
请注意,我在INNER JOIN
和patient
之间使用了history
,并加入了patient
中两个键上的表格。这种类型的连接将返回两个表中的所有匹配记录。
我在其他两个表上使用LEFT JOIN
,即使其他两个表中没有匹配的记录,也会返回所有患者/历史数据。根据您的需要,您可以在这些表格上使用INNER JOIN
。