我有一个带有多个SUM
s 的查询,它给我的值比我预期的要高。如果我将查询缩减为一个SUM
,一切正常,但只要我添加其他SUM
s,我就会得到不正确的值。我尝试在网上查找并尝试了不同的方法,包括更改JOIN
s 和 nested SELECT
s,但仍然没有运气。所有帮助将不胜感激。
SELECT
A.WR_NO WORK_ORDER, A.WR_TYPE_CODE WR_TYPE, B.NAME PLANNER, A.SCHEDULING_POLYGON_CODE AREA, A.FINAL_CLOSE_DATE COMPLETION_DATE, C.ACTUAL_ITEM_AMT EST_ENG,
SUM(D.AFTER_COND_FCT_AMT) EST_CREW, SUM(E.AFTER_COND_FCT_AMT) ASB_CREW, SUM(F.AFTER_COND_FCT_AMT) EST_CONTR, SUM(G.AFTER_COND_FCT_AMT) ASB_CONTR
FROM
WORK_REQUEST A, CC.ALL_PEOPLE B, WR_CONTRIBUTION_VOUCHER C, WR_COST_ESTIMATE D, WR_COST_ESTIMATE E, WR_COST_ESTIMATE F, WR_COST_ESTIMATE G
WHERE
(A.FINAL_CLOSE_DATE BETWEEN TO_DATE ('10/01/2012','MM/DD/YYYY') AND TO_DATE ('10/04/2012','MM/DD/YYYY'))
AND A.ENTRY_PERSON_NO = B.PERSON_NO(+)
AND A.WR_NO = C.WR_NO(+)
AND A.WR_NO = D.WR_NO(+)
AND A.WR_NO = E.WR_NO(+)
AND A.WR_NO = F.WR_NO(+)
AND A.WR_NO = G.WR_NO(+)
AND (C.VOUCHER_CNTRB_TYPE_CODE(+) = 'ENGT')
AND (D.COST_TYPE_CODE(+) = 'LAB' AND D.DESIGN_ASBUILT_DA(+) = 'D' AND D.PROVIDER(+) = 'CO')
AND (E.COST_TYPE_CODE(+) = 'LAB' AND E.DESIGN_ASBUILT_DA(+) = 'A' AND E.PROVIDER(+) = 'CO')
AND (F.COST_TYPE_CODE(+) = 'LAB' AND F.DESIGN_ASBUILT_DA(+) = 'F' AND F.PROVIDER(+) = 'CN')
AND (G.COST_TYPE_CODE(+) = 'LAB' AND G.DESIGN_ASBUILT_DA(+) = 'G' AND G.PROVIDER(+) = 'CN')
GROUP BY
A.WR_NO, A.WR_TYPE_CODE, B.NAME, A.SCHEDULING_POLYGON_CODE, A.FINAL_CLOSE_DATE, C.ACTUAL_ITEM_AMT
ORDER BY 1