1

我正在使用 Oracle 数据库 11g 编写脚本。

我目前有几个嵌套的子查询。我需要从这些子查询之一中检索一个字段,但有一些困难。我目前的脚本是:

SELECT  a.PARTY_ID, a.PARTY_NAME, a.STATUS
        ,a.OBJECT_VERSION_NUMBER, a.PARTY_NUMBER
FROM    HZ_PARTIES a
WHERE   a.PARTY_TYPE = 'ORGANIZATION'
AND     a.STATUS = 'A' and a.party_id = 4402
AND     a.CREATED_BY_MODULE IN ('HZ_CPUI','TCA_V1_API','TCA_FORM_WRAPPER')
AND     (a.PARTY_ID IN (SELECT b.PARTY_ID FROM HZ_CUST_ACCOUNTS b
           WHERE b.CUSTOMER_TYPE = 'R'
           AND b.CUST_ACCOUNT_ID IN (SELECT c.BILL_TO_CUSTOMER_ID FROM RA_CUSTOMER_TRX_ALL c
                    WHERE c.BILL_TO_CUSTOMER_ID IS NOT NULL
                    AND c.LAST_UPDATE_DATE < SYSDATE-100)))

我正在尝试从最后一个嵌套子查询(RA_CUSTOMER_TRX_ALL 表)中选择一个字段“LAST_UPDATE_DATE”。我试图在 SELECT 部分中包含一个选择子查询。和 FROM 部分,但不能将其链接到子查询的最后部分。有人可以帮忙吗?干杯,RussH。

4

1 回答 1

1

一个未经测试的赃物。根据您的数据,您可能必须删除重复项:

SELECT  a.PARTY_ID, a.PARTY_NAME, a.STATUS
        ,a.OBJECT_VERSION_NUMBER, a.PARTY_NUMBER, c.last_update_date
FROM    HZ_PARTIES a JOIN hz_cust_accounts b 
                       ON b.customer_type = 'R' 
                          AND a.party_id = b.party_id
                     JOIN ra_customer_trx_all c 
                       ON b.cust_account_id = c.bill_to_customer_id
                          AND c.last_update_date < SYSDATE-100
WHERE   a.PARTY_TYPE = 'ORGANIZATION'
AND     a.STATUS = 'A' and a.party_id = 4402
AND     a.CREATED_BY_MODULE IN ('HZ_CPUI','TCA_V1_API','TCA_FORM_WRAPPER')
于 2013-09-27T04:21:45.323 回答