AS-IS
SELECT /* [OM-BAT][searchAutoPurchaseConfirmGiftList][자동구매확정 처리 대상(사은품) 목록 조회][홍웅기] 2020.02.27 */
A.OD_NO
, A.OD_SEQ
, A.PROC_SEQ
, IFNULL(A.CLM_NO,'') AS CLM_NO
, A.MB_NO
, A.PUR_CFRM_DVS_CD AS pcdc /* 구매확정구분코드 */
FROM OM_OD_DTL A
WHERE 1=1
AND A.OD_SL_TYP_CD IN ('GOODS_GFT','ORD_GFT') /* 주문판매유형코드 IN (상품사은품, 주문사은품) */
AND A.OD_PRGS_STEP_CD IN ('05','11','12','13','14','15') /* 주문진행단계코드 = 주문완료(05),출고지시(11),상품준비(12),발송완료(13),배송완료(14),수취완료(15) */
AND A.PUR_CFRM_DVS_CD IN ('01', '02') /* 구매확정구분 = 구매미확정(01), 구매확정연장(02) */
AND A.OD_TYP_CD IN ('10', '30') /* 주문유형 = 주문(10), 교환(30) */
AND A.DV_RTRV_DVS_CD = 'DV' /* 배송회수구분 = 배송(DV) */
AND IFNULL(A.EXCP_PROC_DVS_CD, '') = '' /* 예외처리구분코드 = null */
AND (IFNULL(A.OD_QTY,0) - IFNULL(A.CNCL_QTY,0) - IFNULL(A.RTNG_QTY,0) - IFNULL(A.XCHG_QTY,0)) > 0 /* 잔여수량 > 0 */
AND A.PUR_CFRM_BGT_DTTM > DATE_SUB(CURRENT_DATE(), INTERVAL 2 MONTH) /* 구매확정예정일-2개월 */
AND A.PUR_CFRM_BGT_DTTM < DATE_ADD(CURRENT_DATE(), INTERVAL 1 DAY) /* 구매확정예정일 */
/* e쿠폰 기배송건 제외 처리 */
AND NOT EXISTS(
SELECT 1
FROM OM_OD_DTL Z
WHERE Z.OD_NO = A.OD_NO
AND Z.OD_SEQ = A.OD_SEQ
AND Z.PROC_SEQ = A.PROC_SEQ
AND Z.DV_PD_TYP_CD = 'ECPN'
AND Z.ALRD_PROC_DVS_CD = '01'
)
/* 반품요청일이 2021-05-21 이전건 제외(클레임구조개선 배포전 주문 체크) */
AND NOT EXISTS(
SELECT 1
FROM OM_OD_DTL Z
WHERE Z.OD_NO = A.OD_NO
AND (Z.OD_QTY - Z.CNCL_QTY - Z.RTNG_QTY - Z.XCHG_QTY) > 0
AND Z.OD_TYP_CD = '40'
AND Z.OD_PRGS_STEP_CD != '27'
AND Z.CLM_REQ_DTTM < '2021-05-21'
)
LIMIT 2000
;
TO_BE
SELECT /* [OM-BAT][searchAutoPurchaseConfirmGiftList][자동구매확정 처리 대상(사은품) 목록 조회][홍웅기] 2020.02.27 */
A.OD_NO
, A.OD_SEQ
, A.PROC_SEQ
, IFNULL(A.CLM_NO,'') AS CLM_NO
, A.MB_NO
, A.PUR_CFRM_DVS_CD AS pcdc /* 구매확정구분코드 */
FROM OM_OD_DTL A LEFT OUTER JOIN OM_OD_DTL Z ON (A.OD_NO=Z.OD_NO AND A.OD_SEQ=Z.OD_SEQ AND A.PROC_SEQ=Z.PROC_SEQ)
LEFT OUTER JOIN OM_OD_DTL C ON A.OD_NO=C.OD_NO
WHERE 1=1
AND A.OD_SL_TYP_CD IN ('GOODS_GFT','ORD_GFT') /* 주문판매유형코드 IN (상품사은품, 주문사은품) */
AND A.OD_PRGS_STEP_CD IN ('05','11','12','13','14','15') /* 주문진행단계코드 = 주문완료(05),출고지시(11),상품준비(12),발송완료(13),배송완료(14),수취완료(15) */
AND A.PUR_CFRM_DVS_CD IN ('01', '02') /* 구매확정구분 = 구매미확정(01), 구매확정연장(02) */
AND A.OD_TYP_CD IN ('10', '30') /* 주문유형 = 주문(10), 교환(30) */
AND A.DV_RTRV_DVS_CD = 'DV' /* 배송회수구분 = 배송(DV) */
AND IFNULL(A.EXCP_PROC_DVS_CD, '') = '' /* 예외처리구분코드 = null */
AND (IFNULL(A.OD_QTY,0) - IFNULL(A.CNCL_QTY,0) - IFNULL(A.RTNG_QTY,0) - IFNULL(A.XCHG_QTY,0)) > 0 /* 잔여수량 > 0 */
AND A.PUR_CFRM_BGT_DTTM > DATE_SUB(CURRENT_DATE(), INTERVAL 2 MONTH) /* 구매확정예정일-2개월 */
AND A.PUR_CFRM_BGT_DTTM < DATE_ADD(CURRENT_DATE(), INTERVAL 1 DAY) /* 구매확정예정일 */
AND Z.DV_PD_TYP_CD = 'ECPN'
AND Z.ALRD_PROC_DVS_CD = '01'
AND (C.OD_QTY - C.CNCL_QTY - C.RTNG_QTY - C.XCHG_QTY) > 0
AND C.OD_TYP_CD = '40'
AND C.OD_PRGS_STEP_CD != '27'
AND C.CLM_REQ_DTTM < '2021-05-21'
AND Z.OD_NO IS NULL
AND Z.OD_SEQ IS NULL
AND Z.PROC_SEQ IS NULL
AND C.OD_NO IS NULL
LIMIT 2000
;
AS-IS TO-BE 쿼리입니다~!
고수님들 부탁드려여~!
SELECT ... FROM om_od_dtl a LEFT OUTER JOIN om_od_dtl z ON a.od_no = z.od_no AND a.od_seq = z.od_seq AND a.proc_seq = z.proc_seq AND z.dv_pd_typ_cd = 'ECPN' AND z.alrd_proc_dvs_cd = '01' LEFT OUTER JOIN om_od_dtl c ON a.od_no = c.od_no AND c.od_qty - c.cncl_qty - c.rtng_qty - c.xchg_qty > 0 AND c.od_typ_cd = '40' AND c.od_prgs_step_cd != '27' AND c.clm_req_dttm < '2021-05-21' WHERE 1=1 AND ... AND z.od_no IS NULL AND c.od_no IS NULL ;