Oracle
 sql >> Datenbank >  >> RDS >> Oracle

Verbinden mehrerer Tische

Richtig, ich konnte das nicht testen, aber ich würde so etwas tun:

SELECT
    proj_id,
    project_estimates.Q1,
    project_estimates.Q2,
    project_estimates.Q3,
    project_estimates.Q4,
    project_expenditure.Q1,
    project_expenditure.Q2,
    project_expenditure.Q3,
    project_expenditure.Q4
FROM projects
LEFT JOIN project_estimates ON (project_estimates.proj_id = projects.proj_id)
LEFT JOIN project_expenditure ON (project_expenditure.proj_id = projects.proj_id)
WHERE projects.proj_id IN (
    (SELECT proj_id FROM project_estimates WHERE (project_estimates.fy = '2015-16'))
    UNION
    (SELECT proj_id FROM project_expenditure WHERE (project_expenditure.fy = '2015-16'))
GROUP BY proj_id
)
ORDER BY proj_id