0

我想调整以下查询以消除其中指定的 NOT EXIST 子句。你能帮忙吗?

GLT_temp_upload 是临时表,其中 DA_DUEDATE 是分区表,其中包含大量数据。

请帮忙

SELECT  DISTINCT
              batchid,
              store_area,
                 STORE_AREA
              || ','
              || STORE_ID
              || ','
              || SMS_ID
              || ','
              || SMS_SERVICE
              || ','
              || SYNERGY_MODE_ID
              || ','
              || FREQUENCY
              || ','
              || DUEDATE
              || ','
              || STUDY_ID
              || ','
              || YEAR
              || ''
              || WEEK_ID
              ||',Not exist in Da_Duedate'
         FROM GLT_temp_upload upload
        WHERE     upload.batchid = 1
              AND NOT EXISTS
                         (SELECT due.week_id,
                                 due.country_id,
                                 due.year,
                                 due.study_id,
                                 due.store_id,
                                 due.store_area,
                                 due.synergy_mode_id,
                                 upload.batchid,
                                 due.due_date,
                                 upload.sms_service
                            FROM DA_DUEDATE due
                           WHERE     due.store_id = upload.store_id
                                 AND due.study_id = upload.study_id
                                 AND due.store_area = upload.store_area
                                 AND due.frequency = upload.frequency
                                 AND due.sms_service = upload.sms_service
                                 AND due.week_id = upload.week_id
                                 AND due.country_id = upload.country_id
                                 AND due.year = upload.year
                                 AND due.sms_id = upload.sms_id
                                 AND due.synergy_mode_id =
                                        upload.synergy_mode_id)
4

1 回答 1

0

你可以试试 NOT EXISTS / LEFT JOIN / NOT IN

SELECT 1在您的 NOT EXISTS 中,代替列列表就足够了

有时 LEFT JOIN 可能更有益(取决于索引、表的大小等)

SELECT  DISTINCT
              batchid,
              store_area,
                 STORE_AREA
              || ','
              || STORE_ID
              || ','
              || SMS_ID
              || ','
              || SMS_SERVICE
              || ','
              || SYNERGY_MODE_ID
              || ','
              || FREQUENCY
              || ','
              || DUEDATE
              || ','
              || STUDY_ID
              || ','
              || YEAR
              || ''
              || WEEK_ID
              ||',Not exist in Da_Duedate'
         FROM GLT_temp_upload upload left join DA_DUEDATE due
              ON due.store_id = upload.store_id
                 AND due.study_id = upload.study_id
                 AND due.store_area = upload.store_area
                 AND due.frequency = upload.frequency
                 AND due.sms_service = upload.sms_service
                 AND due.week_id = upload.week_id
                 AND due.country_id = upload.country_id
                 AND due.year = upload.year
                 AND due.sms_id = upload.sms_id
                 AND due.synergy_mode_id = upload.synergy_mode_id
        WHERE upload.batchid = 1 and due.store_id is NULL;

我建议您查看执行计划,为您的案例找到最佳解决方案。

于 2014-11-26T11:45:03.113 回答