Minha tabela abaixo mostra as linhas e colunas onde os dados da coluna são filtrados usando uma sintaxe CASE para diferenciar capital de despesa. O problema é que estou recebendo várias linhas por project_ID. Eu preciso de uma linha por project_ID:
Eu preciso que a saída seja:
Aqui está meu Oracle SQl (que inclui muitas outras colunas não mostradas acima):
SELECT
pi.project_id,
pi.project_projectnumber,
pi.project_projectname,
cst.cost1,
CASE WHEN bi.code = '01-00-000' THEN cst.ubr_ROM_Approved
ELSE NULL
END AS CAPITAL_ROM,
CASE WHEN bi.code = '02-00-000'
THEN cst.ubr_ROM_Approved
ELSE NULL
END AS EXPENSE_ROM,
CASE WHEN bi.code = '01-00-000'
THEN cst.ubacf_CD_Approved
ELSE NULL
END AS CAPITAL_ADJ_CD,
CASE WHEN bi.code = '01-00-000'
THEN cst.ubacf_SD_Approved
ELSE NULL
END AS CAPITAL_ADJ_SD,
CASE WHEN bi.code = '01-00-000'
THEN cst.ubacf_DD_Approved
ELSE NULL
END AS CAPITAL_ADJ_DD,
CASE WHEN bi.code = '01-00-000'
THEN cst.ubacf_Budget_Approved
ELSE NULL
END AS CAPITAL_ADJ_Budget,
CASE WHEN bi.code = '02-00-000'
THEN cst.ubacf_CD_Approved
ELSE NULL
END AS EXPENSE_ADJ_CD,
CASE WHEN bi.code = '02-00-000'
THEN cst.ubacf_SD_Approved
ELSE NULL
END AS EXPENSE_ADJ_SD,
CASE WHEN bi.code = '02-00-000'
THEN cst.ubacf_DD_Approved
ELSE NULL
END AS EXPENSE_ADJ_DD,
CASE WHEN bi.code = '02-00-000'
THEN cst.ubacf_Budget_Approved
ELSE NULL
END AS EXPENSE_ADJ_Budget
FROM turnerb_upi_view pi
INNER JOIN turnerb_sys_project_info_view pv ON (pv.pid = pi.project_id)
INNER JOIN turnerb_us_p1_view prj ON (prj.pid = pi.project_id)
INNER JOIN turnerb_budget_summary_viewb cst ON (cst.projectid = pi.project_id)
INNER JOIN turnerb_ubr_view rom ON (rom.project_id = pi.project_id)
INNER JOIN turnerb_ubacf_view badj ON (badj.project_id = pi.project_id)
INNER JOIN turnerb_budgetitem bi ON (bi.budgetid = cst.budgetid)
WHERE pi.project_status = '1'
AND rom.status ='ROM_Approved'
AND (badj.status = 'SD_Approved'
OR badj.status = 'CD_Approved'
OR badj.status = 'DD_Approved'
OR badj.status = 'Budget_Approved')
GROUP BY
pi.project_id,
pi.project_projectnumber,
pi.project_projectname,
bi.code,
cst.cost1,
cst.ubr_ROM_Approved,
cst.ubacf_CD_Approved,
cst.ubacf_SD_Approved,
cst.ubacf_DD_Approved,
cst.ubacf_Budget_Approved
ORDER BY project_projectnumber;