REPT | INPT | INVT | RN |
84 | 87 | RM | 1 |
84 | 88 | RP | 2 |
84 | 89 | RP | 3 |
84 | 93 | RM | 4 |
84 | 94 | RM | 5 |
84 | 95 | RP | 6 |
84 | 96 | RP | 7 |
84 | 99 | RM | 8 |
85 | 1 | RP | 9 |
85 | 2 | RP | 10 |
85 | 4 | RM | 11 |
85 | 5 | RM | 12 |
85 | 6 | RM | 13 |
85 | 7 | RP | 14 |
-- 문제가 이해가 안가요.. 원하는 데이타도 써주세요.. WITH T AS ( SELECT A.REPT, A.INPT, A.INVT, ROW_NUMBER() OVER (ORDER BY REPT, INPT) RN FROM ( SELECT 84 AS REPT, 87 AS INPT, 'RM' AS INVT FROM DUAL UNION SELECT 84 AS REPT, 88 AS INPT, 'RP' AS INVT FROM DUAL UNION SELECT 84 AS REPT, 89 AS INPT, 'RP' AS INVT FROM DUAL UNION SELECT 84 AS REPT, 93 AS INPT, 'RM' AS INVT FROM DUAL UNION SELECT 84 AS REPT, 94 AS INPT, 'RM' AS INVT FROM DUAL UNION SELECT 84 AS REPT, 95 AS INPT, 'RP' AS INVT FROM DUAL UNION SELECT 84 AS REPT, 96 AS INPT, 'RP' AS INVT FROM DUAL UNION SELECT 84 AS REPT, 99 AS INPT, 'RM' AS INVT FROM DUAL UNION SELECT 85 AS REPT, 1 AS INPT, 'RP' AS INVT FROM DUAL UNION SELECT 85 AS REPT, 2 AS INPT, 'RP' AS INVT FROM DUAL UNION SELECT 85 AS REPT, 4 AS INPT, 'RM' AS INVT FROM DUAL UNION SELECT 85 AS REPT, 5 AS INPT, 'RM' AS INVT FROM DUAL UNION SELECT 85 AS REPT, 6 AS INPT, 'RM' AS INVT FROM DUAL UNION SELECT 85 AS REPT, 7 AS INPT, 'RP' AS INVT FROM DUAL) A ) SELECT REPT ,INPT ,INVT ,MIN(RN) OVER(PARTITION BY INPT - RN ) MIN_VAL ,MAX(RN) OVER(PARTITION BY INPT - RN ) MAX_VAL FROM T ORDER BY RN
WITH t AS ( SELECT 84 rept, 87 inpt, 'RM' invt FROM dual UNION ALL SELECT 84, 88, 'RP' FROM dual UNION ALL SELECT 84, 89, 'RP' FROM dual UNION ALL SELECT 84, 93, 'RM' FROM dual UNION ALL SELECT 84, 94, 'RM' FROM dual UNION ALL SELECT 84, 95, 'RP' FROM dual UNION ALL SELECT 84, 96, 'RP' FROM dual UNION ALL SELECT 84, 99, 'RM' FROM dual UNION ALL SELECT 85, 1, 'RP' FROM dual UNION ALL SELECT 85, 2, 'RP' FROM dual UNION ALL SELECT 85, 4, 'RM' FROM dual UNION ALL SELECT 85, 5, 'RM' FROM dual UNION ALL SELECT 85, 6, 'RM' FROM dual UNION ALL SELECT 85, 7, 'RP' FROM dual ) SELECT MIN(rn_min) rn_min , MAX(rn_max) rn_max FROM (SELECT invt , MIN(rn) rn_min , MAX(rn) rn_max , SUM(DECODE(invt, 'RM', 1)) OVER(ORDER BY MIN(rn)) grp FROM (SELECT rept, inpt, invt , ROW_NUMBER() OVER(ORDER BY rept, inpt) rn , ROW_NUMBER() OVER(PARTITION BY invt ORDER BY rept, inpt) rn1 FROM t ) GROUP BY invt, rn - rn1 ) GROUP BY grp ORDER BY grp ;