2017-06-12 13 views
0

私はOracleシステムからいくつかのデータを抽出するために以下のクエリを設計しました。クエリは正常に動作し、正しい情報が抽出されます。問題は、Puchase Order(PO_TOTAL_VALUEフィールド)の合計値を返すことになっている列の問題です。これは、購買発注を構成する3つの明細の合計を返します。むしろ、購買発注の3つの明細とは関係のない未知の合計を返します。また、Accessのデザインビューにクエリのスクリーンショットを掲載しました。私が間違ったことを誰に教えてもらえますか?最後にアクセスのクエリが不正な合計を返す

SELECT APPS_PO_HEADERS_ALL.PO_HEADER_ID, APPS_PO_HEADERS_ALL.SEGMENT1, APPS_PO_REQUISITION_LINES_ALL.ATTRIBUTE1, IIf([APPS_XXWRP_SERVICE_REG_ALL]![DOCUMENT_TYPE]="","-",IIf([APPS_XXWRP_SERVICE_REG_ALL]![DOCUMENT_TYPE]="APW","AGREEMENT FOR PERFORMANCE OF WORK",IIf([APPS_XXWRP_SERVICE_REG_ALL]![DOCUMENT_TYPE]="APWEMER","AGREEMENT FOR PERFORMANCE OF WORK - EMERGENCY",IIf([APPS_XXWRP_SERVICE_REG_ALL]![DOCUMENT_TYPE]="CONS","CONSULTANT",IIf([APPS_XXWRP_SERVICE_REG_ALL]![DOCUMENT_TYPE]="CONCEMER","CONSULTANT - EMERGENCY",IIf([APPS_XXWRP_SERVICE_REG_ALL]![DOCUMENT_TYPE]="DFC","DIRECT FINANCIAL CONTRIBUTION",IIf([APPS_XXWRP_SERVICE_REG_ALL]![DOCUMENT_TYPE]="FELLOW","FELLOWSHIP",IIf([APPS_XXWRP_SERVICE_REG_ALL]![DOCUMENT_TYPE]="GENEXT","GENERAL EXTERNAL SERVICES",IIf([APPS_XXWRP_SERVICE_REG_ALL]![DOCUMENT_TYPE]="IMPRESTCC","IMPREST/CREDIT CARD",IIf([APPS_XXWRP_SERVICE_REG_ALL]![DOCUMENT_TYPE]="IS","INTERNAL SERVICES",IIf([APPS_XXWRP_SERVICE_REG_ALL]![DOCUMENT_TYPE]="LOA","LETTER OF AGREEMENT",IIf([APPS_XXWRP_SERVICE_REG_ALL]![DOCUMENT_TYPE]="TSA","TECHNICAL SERVICE AGREEMENT")))))))))))) AS [DOCUMENT TYPE (SERVICES)], IIf([APPS_XXWRP_GOODS_REG_ALL]![PROCUREMENT_TYPE]="","-",IIf([APPS_XXWRP_GOODS_REG_ALL]![PROCUREMENT_TYPE]="UN","Procurement for UN/NGO",IIf([APPS_XXWRP_GOODS_REG_ALL]![PROCUREMENT_TYPE]="SP","Standard Procurement",IIf([APPS_XXWRP_GOODS_REG_ALL]![PROCUREMENT_TYPE]="RP","Reimbursable Procurement",IIf([APPS_XXWRP_GOODS_REG_ALL]![PROCUREMENT_TYPE]="EMER","EMERGENCY"))))) AS [DOCUMENT TYPE (GOODS)], HR_HR_ALL_ORGANIZATION_UNITS.NAME, APPS_PO_HEADERS_ALL.CREATION_DATE, APPS_PO_HEADERS_ALL.AUTHORIZATION_STATUS, APPS_PO_HEADERS_ALL.APPROVED_DATE, APPS_PO_HEADERS_ALL.COMMENTS, APPS_PO_HEADERS_ALL.CLOSED_DATE, APPS_PO_HEADERS_ALL.CLOSED_CODE, AP_AP_INVOICE_DISTRIBUTIONS_ALL.INVOICE_ID, AP_AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE, APPS_PO_VENDORS.VENDOR_NAME, APPS_PO_HEADERS_ALL.VENDOR_ID, AP_AP_INVOICES_ALL.INVOICE_DATE, AP_AP_INVOICES_ALL.INVOICE_NUM, AP_AP_INVOICES_ALL.INVOICE_AMOUNT, AP_AP_INVOICES_ALL.INVOICE_CURRENCY_CODE, AP_AP_INVOICES_ALL.GL_DATE, AP_AP_INVOICES_ALL.PAYMENT_CURRENCY_CODE, AP_AP_INVOICES_ALL.PAYMENT_CROSS_RATE, AP_AP_INVOICES_ALL.DESCRIPTION, AP_AP_INVOICES_ALL.EXCHANGE_RATE, AP_AP_INVOICES_ALL.BASE_AMOUNT, Sum(IIf(Nz([APPS_PO_LINES_ALL]![QUANTITY],0)*Nz([APPS_PO_LINES_ALL]![UNIT_PRICE],0)*Nz([APPS_PO_DISTRIBUTIONS_ALL]![RATE],1)=0,Nz([APPS_PO_LINES_ALL]![AMOUNT],0)*Nz([APPS_PO_DISTRIBUTIONS_ALL]![RATE],1),Nz([APPS_PO_LINES_ALL]![QUANTITY],0)*Nz([APPS_PO_LINES_ALL]![UNIT_PRICE],0)*Nz([APPS_PO_DISTRIBUTIONS_ALL]![RATE],1))) AS PO_TOTAL_VALUE, APPS_PO_LINES_ALL.QUANTITY, APPS_PO_LINES_ALL.UNIT_PRICE, APPS_PO_LINES_ALL.AMOUNT, APPS_PO_DISTRIBUTIONS_ALL.Rate 
FROM (((((((((((APPS_PO_HEADERS_ALL LEFT JOIN APPS_PO_DISTRIBUTIONS_ALL ON APPS_PO_HEADERS_ALL.PO_HEADER_ID = APPS_PO_DISTRIBUTIONS_ALL.PO_HEADER_ID) LEFT JOIN APPS_PO_REQ_DISTRIBUTIONS_ALL ON APPS_PO_DISTRIBUTIONS_ALL.REQ_DISTRIBUTION_ID = APPS_PO_REQ_DISTRIBUTIONS_ALL.DISTRIBUTION_ID) LEFT JOIN APPS_PO_REQUISITION_LINES_ALL ON APPS_PO_REQ_DISTRIBUTIONS_ALL.REQUISITION_LINE_ID = APPS_PO_REQUISITION_LINES_ALL.REQUISITION_LINE_ID) LEFT JOIN APPS_PA_PROJECTS_ALL ON APPS_PO_DISTRIBUTIONS_ALL.PROJECT_ID = APPS_PA_PROJECTS_ALL.PROJECT_ID) LEFT JOIN AP_AP_INVOICE_DISTRIBUTIONS_ALL ON APPS_PO_DISTRIBUTIONS_ALL.PO_DISTRIBUTION_ID = AP_AP_INVOICE_DISTRIBUTIONS_ALL.PO_DISTRIBUTION_ID) LEFT JOIN AP_AP_INVOICES_ALL ON AP_AP_INVOICE_DISTRIBUTIONS_ALL.INVOICE_ID = AP_AP_INVOICES_ALL.INVOICE_ID) LEFT JOIN HR_HR_ALL_ORGANIZATION_UNITS ON APPS_PA_PROJECTS_ALL.CARRYING_OUT_ORGANIZATION_ID = HR_HR_ALL_ORGANIZATION_UNITS.ORGANIZATION_ID) LEFT JOIN APPS_XXWRP_SERVICE_REG_ALL ON APPS_PO_HEADERS_ALL.PO_HEADER_ID = APPS_XXWRP_SERVICE_REG_ALL.PO_HEADER_ID) LEFT JOIN APPS_PO_VENDORS ON APPS_PO_HEADERS_ALL.VENDOR_ID = APPS_PO_VENDORS.VENDOR_ID) LEFT JOIN APPS_PO_LINES_ALL ON (APPS_PO_DISTRIBUTIONS_ALL.PO_HEADER_ID = APPS_PO_LINES_ALL.PO_HEADER_ID) AND (APPS_PO_DISTRIBUTIONS_ALL.PO_LINE_ID = APPS_PO_LINES_ALL.PO_LINE_ID)) LEFT JOIN APPS_XXWRP_GOODS_LINES_ALL ON APPS_PO_HEADERS_ALL.PO_HEADER_ID = APPS_XXWRP_GOODS_LINES_ALL.PO_HEADER_ID) LEFT JOIN APPS_XXWRP_GOODS_REG_ALL ON APPS_XXWRP_GOODS_LINES_ALL.REGISTRATION_ID = APPS_XXWRP_GOODS_REG_ALL.REGISTRATION_ID 
GROUP BY APPS_PO_HEADERS_ALL.PO_HEADER_ID, APPS_PO_HEADERS_ALL.SEGMENT1, APPS_PO_REQUISITION_LINES_ALL.ATTRIBUTE1, IIf([APPS_XXWRP_SERVICE_REG_ALL]![DOCUMENT_TYPE]="","-",IIf([APPS_XXWRP_SERVICE_REG_ALL]![DOCUMENT_TYPE]="APW","AGREEMENT FOR PERFORMANCE OF WORK",IIf([APPS_XXWRP_SERVICE_REG_ALL]![DOCUMENT_TYPE]="APWEMER","AGREEMENT FOR PERFORMANCE OF WORK - EMERGENCY",IIf([APPS_XXWRP_SERVICE_REG_ALL]![DOCUMENT_TYPE]="CONS","CONSULTANT",IIf([APPS_XXWRP_SERVICE_REG_ALL]![DOCUMENT_TYPE]="CONCEMER","CONSULTANT - EMERGENCY",IIf([APPS_XXWRP_SERVICE_REG_ALL]![DOCUMENT_TYPE]="DFC","DIRECT FINANCIAL CONTRIBUTION",IIf([APPS_XXWRP_SERVICE_REG_ALL]![DOCUMENT_TYPE]="FELLOW","FELLOWSHIP",IIf([APPS_XXWRP_SERVICE_REG_ALL]![DOCUMENT_TYPE]="GENEXT","GENERAL EXTERNAL SERVICES",IIf([APPS_XXWRP_SERVICE_REG_ALL]![DOCUMENT_TYPE]="IMPRESTCC","IMPREST/CREDIT CARD",IIf([APPS_XXWRP_SERVICE_REG_ALL]![DOCUMENT_TYPE]="IS","INTERNAL SERVICES",IIf([APPS_XXWRP_SERVICE_REG_ALL]![DOCUMENT_TYPE]="LOA","LETTER OF AGREEMENT",IIf([APPS_XXWRP_SERVICE_REG_ALL]![DOCUMENT_TYPE]="TSA","TECHNICAL SERVICE AGREEMENT")))))))))))), IIf([APPS_XXWRP_GOODS_REG_ALL]![PROCUREMENT_TYPE]="","-",IIf([APPS_XXWRP_GOODS_REG_ALL]![PROCUREMENT_TYPE]="UN","Procurement for UN/NGO",IIf([APPS_XXWRP_GOODS_REG_ALL]![PROCUREMENT_TYPE]="SP","Standard Procurement",IIf([APPS_XXWRP_GOODS_REG_ALL]![PROCUREMENT_TYPE]="RP","Reimbursable Procurement",IIf([APPS_XXWRP_GOODS_REG_ALL]![PROCUREMENT_TYPE]="EMER","EMERGENCY"))))), HR_HR_ALL_ORGANIZATION_UNITS.NAME, APPS_PO_HEADERS_ALL.CREATION_DATE, APPS_PO_HEADERS_ALL.AUTHORIZATION_STATUS, APPS_PO_HEADERS_ALL.APPROVED_DATE, APPS_PO_HEADERS_ALL.COMMENTS, APPS_PO_HEADERS_ALL.CLOSED_DATE, APPS_PO_HEADERS_ALL.CLOSED_CODE, AP_AP_INVOICE_DISTRIBUTIONS_ALL.INVOICE_ID, AP_AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE, APPS_PO_VENDORS.VENDOR_NAME, APPS_PO_HEADERS_ALL.VENDOR_ID, AP_AP_INVOICES_ALL.INVOICE_DATE, AP_AP_INVOICES_ALL.INVOICE_NUM, AP_AP_INVOICES_ALL.INVOICE_AMOUNT, AP_AP_INVOICES_ALL.INVOICE_CURRENCY_CODE, AP_AP_INVOICES_ALL.GL_DATE, AP_AP_INVOICES_ALL.PAYMENT_CURRENCY_CODE, AP_AP_INVOICES_ALL.PAYMENT_CROSS_RATE, AP_AP_INVOICES_ALL.DESCRIPTION, AP_AP_INVOICES_ALL.EXCHANGE_RATE, AP_AP_INVOICES_ALL.BASE_AMOUNT, APPS_PO_LINES_ALL.QUANTITY, APPS_PO_LINES_ALL.UNIT_PRICE, APPS_PO_LINES_ALL.AMOUNT, APPS_PO_DISTRIBUTIONS_ALL.Rate 
HAVING (((APPS_PO_HEADERS_ALL.SEGMENT1)="201127602") AND ((APPS_PO_HEADERS_ALL.CREATION_DATE)>[AP_AP_INVOICES_ALL]![INVOICE_DATE])); 

Query Result with Error

Query design in Access

+1

ジョインに基づく合計の一般的な問題は、どこに重複するローがある場合は、結果が乗算されることです。しかしそれ以上に、何か複雑なものを1つのクエリに入れることはお勧めできません。理解してデバッグするのが非常に難しくなります。必要に応じて中間データを生成するいくつかの手順で書き直すことを検討する必要があります。 –

+0

@ Barattolo_67 MS Accessを使用してOracle E Bizデータベース用のSQLを作成していますか? –

+0

私は組織のレプリカOracle Financialsデータベースへのアクセスを接続しました。 –

答えて

0

私は、クエリに基づいてアクセスレポートの作成、レポート自体に各POの合計値をcaluclatingことで、彼の問題を解決しました。

関連する問題