sql >> Databasteknik >  >> RDS >> Oracle

slå samman flera bord

Okej, jag kunde inte testa den här atm men jag skulle göra något så här:

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


  1. Hur man släpper en tabell i SQL

  2. Hämta/lagra alla relaterade skådespelare i Freebase

  3. generera utvalda alternativ med hjälp av php-matriser

  4. Fel 404 hittades inte med EM 12c