WITH t AS
(
SELECT 560 seq, 1 id, 'insrd_cd' item, '' v1, '2222222' v2, '20130903' sdt, '20130820' rdt FROM dual
UNION ALL SELECT 560, 1, 'insrd_nm' , '' , '노태자' , '20130903', '20130820' FROM dual
UNION ALL SELECT 560, 1, 'insrd_rlatn', '' , '02' , '20130903', '20130820' FROM dual
UNION ALL SELECT 560, 1, 'join_yn' , '' , '1' , '20130903', '20130820' FROM dual
UNION ALL SELECT 562, 1, 'insrd_rlatn', '02', '05' , '20130905', '20130820' FROM dual
UNION ALL SELECT 562, 1, 'insrd_cd' , '2222222', '2222223', '20130905', '20130820' FROM dual
UNION ALL SELECT 562, 1, 'insrd_nm' , '노태자', '김태자' , '20130905', '20130820' FROM dual
UNION ALL SELECT 561, 1, 'insrd_rlatn', '02', '07' , '20130910', '20130820' FROM dual
)
SELECT MIN(insrd_cd ) KEEP(DENSE_RANK LAST ORDER BY seq) insrd_cd
, MIN(insrd_nm ) KEEP(DENSE_RANK LAST ORDER BY seq) insrd_nm
, MIN(insrd_rlatn) KEEP(DENSE_RANK LAST ORDER BY seq) insrd_rlatn
, sdt
, nvl(MAX(edt),'20140903') edt
, MAX(rdt) rdt
FROM (
SELECT seq
, LAST_VALUE(MIN(DECODE(item, 'insrd_cd', v2))
IGNORE NULLS) OVER(ORDER BY sdt, seq) insrd_cd
, LAST_VALUE(MIN(DECODE(item, 'insrd_nm', v2))
IGNORE NULLS) OVER(ORDER BY sdt, seq) insrd_nm
, LAST_VALUE(MIN(DECODE(item, 'insrd_rlatn', v2))
IGNORE NULLS) OVER(ORDER BY sdt, seq) insrd_rlatn
, MAX(DECODE(item, 'join_yn', v1, '0')) join_yn
, sdt
, LEAD(sdt) OVER(ORDER BY sdt, seq) edt
, rdt
FROM t
WHERE id = 1
GROUP BY seq, sdt, rdt
)
WHERE join_yn = '0'
GROUP BY sdt
ORDER BY sdt
-> 마농님이 짜주신 위쿼리 내역을 살펴보던중에 조회값을 제가 원하는대로 변경을 하고싶은데.
현재조회값은 이렇게 나오는데..
INSRD_CD |
INSRD_NM |
INSRD_RLATN |
SDT |
EDT |
RDT |
2222222 |
노태자 |
02 |
20130903 |
20130905 |
20130820 |
2222223 |
김태자 |
05 |
20130905 |
20130910 |
20130820 |
2222223 |
김태자 |
07 |
20130910 |
20140903 |
20130820 |