我的下表显示了使用 CASE 语法过滤列数据以区分资本和费用的行和列。问题是每个project_ID 我得到多行。我需要每个 project_ID 一行:
我需要输出为:
这是我的 Oracle SQl(包括上面未显示的许多其他列):
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;