문제를 폴다풀다 답답해서 문의 드립니다.
select master_id, oper_Dt, S_val1, Sval2
from price_the
select master_id ,START_DT, END_DT, val1, val2, val3
from
(
SELECT master_id ,START_DT, END_DT, val1, val2, val3
, ROW_NUMBER() OVER (PARTITION BY master_id ORDER BY START_DT) RN
FROM PRICE_MON
where master_id = '114501'
and end_dt >= '20221101'
)
where rn = 1
두개의 테이블을 가지고 조인을 하려고 하는데 조인이 안되네요
제가 얻고자 하는 정보는 master_id, oper_Dt, S_val1, Sval2, val1, val2, val3 입니다.
임시 방편으로 만든 쿼리가 있는데 뭔가 비효율적이라 문의 드립니다.
select master_id, oper_Dt, S_val1, Sval2
, (
select val1
from
(
SELECT master_id ,START_DT, END_DT, val1, val2, val3
, ROW_NUMBER() OVER (PARTITION BY master_id ORDER BY START_DT) RN
FROM PRICE_MON B
where B.master_id = A.master_id
and B.end_dt >= a.oper_dt
)
where rn = 1
) val1
, (
select val2
from
(
SELECT master_id ,START_DT, END_DT, val1, val2, val3
, ROW_NUMBER() OVER (PARTITION BY master_id ORDER BY START_DT) RN
FROM PRICE_MON B
where B.master_id = A.master_id
and B.end_dt >= a.oper_dt
)
where rn = 1
) val2
, (
select val3
from
(
SELECT master_id ,START_DT, END_DT, val1, val2, val3
, ROW_NUMBER() OVER (PARTITION BY master_id ORDER BY START_DT) RN
FROM PRICE_MON B
where B.master_id = A.master_id
and B.end_dt >= a.oper_dt
)
where rn = 1
) val3
from price_the a
개선할수 있는 방법이 있을까요???
|