WITH t AS ( SELECT '2001.01' dt, 0 amt FROM dual UNION ALL SELECT '2001.02', 0 FROM dual UNION ALL SELECT '2001.03', 1 FROM dual UNION ALL SELECT '2001.04', 0 FROM dual UNION ALL SELECT '2001.05', 0 FROM dual UNION ALL SELECT '2001.06', 0 FROM dual ) SELECT MIN(dt) sdt , MAX(dt) edt , amt , COUNT(*) cnt FROM (SELECT dt, amt , ROW_NUMBER() OVER(ORDER BY dt) rn1 , ROW_NUMBER() OVER(PARTITION BY amt ORDER BY dt) rn2 FROM t ) GROUP BY rn1 - rn2, amt ORDER BY sdt ;
음... 많이 보던 스타일의 쿼리군요.
쏘...