며칠전 NVL 관련하여 많은 공부가 되고 있습니다. 정말 감사드립니다.
다른 케이스인데, 심플한 쿼리인데도 이 부분도 속도가 안나오는 이유는 무엇인지 조언 부탁드립니다.
유사 케이스라 생각을 했는데, 이건 또 다른 방향으로의 개선이 필요한 것인지요..
SELECT A.req_no AS vbelv --오더번호(출하요청)
,A.req_item_no AS posnv --싱위오더번호아이템 순번
,A.p_req_no --오더번호
,sap_order_no AS vbeln --재고오더
,sap_order_item_no AS posnr --품목번호
,To_char(To_date(A.ord_dt), 'YYYY-MM-DD') AS ORD_DT --오더입력일
,'R' AS status --진행상태
,W_fn_code_filter_nm('MC1102', 1, A.req_status, NULL) AS REQ_STATUS_NM
,'R' AS gi_status --진행상태
,A.steel_kind AS skind --강종
,W_fn_code_filter_nm('SKIND', 1, A.steel_kind, NULL) AS skind_nm --강종명
,A.steel_standard AS sstan --규격
,A.steel_length AS slength --길이
,A.ton_wgt --결속구분
,W_fn_code_filter_nm('MC1101', 1, A.ton_wgt, 'KO') AS TON_WGT_NM --결속구분명
,from_plnt_no AS WERKS_CD --플랜트
,rmn_qty - (SELECT Nvl(SUM(req_qty), 0)
FROM (SELECT p_req_no,
req_qty
FROM sales.w_tb_delivery_order_master ST
WHERE ST.p_req_no = A.req_no
AND req_status = 'C'
AND ST.cust_gb = CASE
WHEN Length(temp1) > 13 THEN
'70'
ELSE ST.cust_gb
END
AND use_yn = 'Y')) AS RMN_QTY
,A.item_type
FROM w_tb_wos_order_master M inner join sales.w_tb_delivery_order_master a
ON M.order_master_id = A.p_req_no
left outer join w_tb_wos_customer_delivery B ON ( A.arrive_code = B.seq )
left outer join w_vw_sy_customer_master C ON ( A.cust_no = C.kunag AND A.site_no = C.kunwe
AND A.comp_cd = C.company_cd )
left outer join w_vw_sy_customer_master C2 ON ( A.reg_user = C2.kunwe AND A.comp_cd = C2.company_cd )
left outer join w_tb_sy_member_master E ON ( A.reg_user = E.member_id )
WHERE A.rmn_qty > 0
AND A.p_req_no LIKE 'OMI%'
AND A.use_yn = 'Y'
AND A.dlv_req_dt BETWEEN '20230702' AND '20230708'
ORDER BY A.req_no DESC