WITH T(PROD_CODE, DT) AS (
SELECT 'A1','20120101' FROM DUAL UNION ALL
SELECT 'A2','20120501' FROM DUAL UNION ALL
SELECT 'A3','20121201' FROM DUAL UNION ALL
SELECT 'B1','20120301' FROM DUAL UNION ALL
SELECT 'B2','20120601' FROM DUAL UNION ALL
SELECT 'C1','20120701' FROM DUAL UNION ALL
SELECT 'C2','20120801' FROM DUAL UNION ALL
SELECT 'C3','20121001' FROM DUAL UNION ALL
SELECT 'C4','20121201' FROM DUAL
)
SELECT
PROD_CODE,
DT,
LEAD(dt, 1, '99991231') OVER(PARTITION BY SUBSTR(prod_code, 1, 1) ORDER BY dt) NEXT_DT
FROM
T
'DB > Oracle 활용' 카테고리의 다른 글
구간에서 원하는 결과값 구하기 (0) | 2016.06.22 |
---|---|
달력 팝업 창 쿼리 만들기 (0) | 2016.01.20 |