제가 질문을 잘 못한것 같습니다.
WITH T AS(
SELECT '20101101' DT, '01' GB FROM DUAL UNION ALL
SELECT '20101102', '01' FROM DUAL UNION ALL
SELECT '20101103', '02' FROM DUAL UNION ALL
SELECT '20101104', '01' FROM DUAL UNION ALL
SELECT '20101105', '01' FROM DUAL UNION ALL
SELECT '20101106', '02' FROM DUAL UNION ALL
SELECT '20101107', '02' FROM DUAL UNION ALL
SELECT '20101108', '01' FROM DUAL UNION ALL
SELECT '20101109', '01' FROM DUAL
)
SELECT
DT
,GB
,DECODE(GB,'01',0,RANK()OVER(PARTITION BY GB ORDER BY DT DESC)) COUNT
FROM T
ORDER BY DT
하면 20101103 이 4가 나오는데 1이나와야되고요.. 20101106 은 2, 20101107 은 1 이 나와야되는거에요..
즉 가장 가까운 01 이 나올때 까지의 COUNT 를 하는 것입니다.
감사합니다.
답변좀 주세요..