2013-01-17 25 views
2

我在Oracle APEX中工作。我正在從以下四個表Patient History Junction and Disease中做出報告,但無法完成。從四個表中做出報告

我想SELECT

Pat_Name,Pat_Age`從耐心表

Treated_By,Sys_Date從歷史表

從疾病表

。還有Dis_Name是History and Disease之間的Junction表。以下是上述場景圖。

enter image description here

回答

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

請注意,我在patienthistory之間使用了INNER JOIN,並在patient的兩個鍵上加入了表格。這種類型的連接將返回兩個表中的所有匹配記錄。

我在其他兩張桌子上使用了LEFT JOIN,即使其他兩張桌子中沒有匹配的記錄,它也會返回所有的病人/病史數據。根據您的需要,您可能可以在這些表上使用INNER JOIN

+0

Thanks @bluefeet .. It Works –