0

複数の を含むクエリがあり、SUM予想よりも高い値が得られます。クエリを 1 つだけに削減すると、SUMすべて正常に動作しますが、他の s を追加するとすぐに、SUM間違った値が得られます。私はオンラインで調べてみたり、JOINs や入れ子になった s を変更するなど、さまざまなアプローチを試みましSELECTたが、まだ運がありません。すべての助けをいただければ幸いです。

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
4

2 に答える 2

0

結合によって行が乗算されるため、予想よりも高い値が得られます。データ構造を理解していなければ、外部の人が問題の場所を正確に伝えることは困難です。

この問題の解決策は、計算に必要なテーブルでのみ合計を計算することです。その後、追加のテーブル/サマリーに参加できます。

ところで、実際には適切なJOIN構文を使用する必要があります。結合を意味するコンマの使用はかなり時代遅れであり、クエリの理解を難しくしています。

于 2012-12-04T22:34:17.517 に答える
0

選択する

WO_ID WORK_ORDER,
WR_TYPE_CODE WR_TYPE,
NAME PLANNER,
SCHEDULING_POLYGON_CODE AREA,
FINAL_CLOSE_DATE COMPLETE_DATE,
SUM (EENG) AS "ENG_TIME",
SUM (ECREW) AS "EST_CREW",
SUM (ACREW) AS "ASB_CREW",
SUM (ECONT) AS "EST_CONTR",
SUM (ACONT) AS "ASB_CONTR"

から

(SELECT
    A.WO_ID,
    A.WR_TYPE_CODE,
    B.NAME,
    A. SCHEDULING_POLYGON_CODE,
    A.FINAL_CLOSE_DATE,
    C.ACTUAL_ITEM_AMT AS "EENG",
    0 "ECREW",
    0 "ACREW",
    0 "ECONT",
    0 "ACONT"
FROM
    WORK_REQUEST A,
    CC.ALL_PEOPLE B,
    WR_CONTRIBUTION_VOUCHER C
WHERE
    (A.FINAL_CLOSE_DATE BETWEEN TO_DATE ('10/01/2012','MM/DD/YYYY') AND TO_DATE ('10/31/2012','MM/DD/YYYY'))
    AND A.ENTRY_PERSON_NO = B.PERSON_NO
    AND A.WR_NO = C.WR_NO
    AND (C.VOUCHER_CNTRB_TYPE_CODE = 'ENGT')

連合

SELECT
    A.WO_ID,
    A.WR_TYPE_CODE,
    B.NAME,
    A. SCHEDULING_POLYGON_CODE,
    A.FINAL_CLOSE_DATE,
    0 "EENG",
    D.AFTER_COND_FCT_AMT AS "ECREW",
    0 "ACREW",
    0 "ECONT",
    0 "ACONT"
FROM
    WORK_REQUEST A,
    CC.ALL_PEOPLE B,
    WR_COST_ESTIMATE D
WHERE
    (A.FINAL_CLOSE_DATE BETWEEN TO_DATE ('10/01/2012','MM/DD/YYYY') AND TO_DATE ('10/31/2012','MM/DD/YYYY'))
    AND A.ENTRY_PERSON_NO = B.PERSON_NO
    AND A.WR_NO = D.WR_NO
    AND (D.COST_TYPE_CODE = 'LAB' AND D.DESIGN_ASBUILT_DA = 'D' AND D.PROVIDER = 'CO')

連合

SELECT
    A.WO_ID,
    A.WR_TYPE_CODE,
    B.NAME,
    A. SCHEDULING_POLYGON_CODE,
    A.FINAL_CLOSE_DATE,
    0 "EENG",
    0 "ECREW",
    E. AFTER_COND_FCT_AMT AS "ACREW",
    0 "ECONT",
    0 "ACONT"
FROM
    WORK_REQUEST A,
    CC.ALL_PEOPLE B,
    WR_COST_ESTIMATE E
WHERE
    (A.FINAL_CLOSE_DATE BETWEEN TO_DATE ('10/01/2012','MM/DD/YYYY') AND TO_DATE ('10/31/2012','MM/DD/YYYY'))
    AND A.ENTRY_PERSON_NO = B.PERSON_NO
    AND A.WR_NO = E.WR_NO
    AND (E.COST_TYPE_CODE = 'LAB' AND E.DESIGN_ASBUILT_DA = 'A' AND E.PROVIDER = 'CO')

連合

SELECT
    A.WO_ID,
    A.WR_TYPE_CODE,
    B.NAME,
    A. SCHEDULING_POLYGON_CODE,
    A.FINAL_CLOSE_DATE,
    0 "EENG",
    0 "ECREW",
    0 "ACREW",
    F.AFTER_COND_FCT_AMT AS "ECONT",
    0 "ACONT"
FROM
    WORK_REQUEST A,
    CC.ALL_PEOPLE B,
    WR_COST_ESTIMATE F
WHERE
    (A.FINAL_CLOSE_DATE BETWEEN TO_DATE ('10/01/2012','MM/DD/YYYY') AND TO_DATE ('10/31/2012','MM/DD/YYYY'))
    AND A.ENTRY_PERSON_NO = B.PERSON_NO
    AND A.WR_NO = F.WR_NO
    AND (F.COST_TYPE_CODE = 'LAB' AND F.DESIGN_ASBUILT_DA = 'D' AND F.PROVIDER = 'CN')

連合

SELECT
    A.WO_ID,
    A.WR_TYPE_CODE,
    B.NAME,
    A. SCHEDULING_POLYGON_CODE,
    A.FINAL_CLOSE_DATE,
    0 "EENG",
    0 "ECREW",
    0 "ACREW",
    0 "ECONT",
    G.AFTER_COND_FCT_AMT AS "ACONT"
FROM
    WORK_REQUEST A,
    CC.ALL_PEOPLE B,
    WR_COST_ESTIMATE G
WHERE
    (A.FINAL_CLOSE_DATE BETWEEN TO_DATE ('10/01/2012','MM/DD/YYYY') AND TO_DATE ('10/31/2012','MM/DD/YYYY'))
    AND A.ENTRY_PERSON_NO = B.PERSON_NO
    AND A.WR_NO = G.WR_NO
    AND (G.COST_TYPE_CODE = 'LAB' AND G.DESIGN_ASBUILT_DA = 'A' AND G.PROVIDER = 'CN'))

グループ化

WO_ID, WR_TYPE_CODE, NAME, SCHEDULING_POLYGON_CODE, FINAL_CLOSE_DATE

1ASCで注文

于 2012-12-06T14:56:43.997 に答える