|
자료 : 기준일자 영업유무 19810101 Y 19810103 N 19810104 Y 19810105 N 19810106 N 19810107 N 19810108 N 19810109 N 19810111 Y 일 경우
결과 : 기준일자로 정렬해서 위에서 부터 Y 갯수를 COUNT 하기 기준일자 영업유무 Y갯수 19810101 Y 1 19810103 N 1 19810104 Y 2 19810105 N 2 19810106 N 2 19810107 N 2 19810108 N 2 19810109 N 2 19810111 Y 3;
WITH T AS ( SELECT '19810101' DAT, 'Y' YN FROM DUAL UNION ALL SELECT '19810103' DAT, 'N' YN FROM DUAL UNION ALL SELECT '19810104' DAT, 'Y' YN FROM DUAL UNION ALL SELECT '19810105' DAT, 'N' YN FROM DUAL UNION ALL SELECT '19810106' DAT, 'N' YN FROM DUAL UNION ALL SELECT '19810107' DAT, 'N' YN FROM DUAL UNION ALL SELECT '19810108' DAT, 'N' YN FROM DUAL UNION ALL SELECT '19810109' DAT, 'N' YN FROM DUAL UNION ALL SELECT '19810111' DAT, 'Y' YN FROM DUAL ) SELECT DAT, YN, COUNT( DECODE( YN, 'Y', 1 ) ) OVER( ORDER BY DAT ASC ) GRP FROM T ;
|
|
자료 : 기준일자 영업유무 19810101 Y 19810103 N 19810104 Y 19810105 N 19810106 N 19810107 N 19810108 N 19810109 N 19810111 Y 일 경우
결과 : 기준일자로 정렬해서 위에서 휴무일자를 제외한 영업일자를 찾아오기 기준일자 영업유무 영업일자 19810101 Y 19810101 19810103 N 19810104 19810104 Y 19810104 19810105 N 19810111 19810106 N 19810111 19810107 N 19810111 19810108 N 19810111 19810109 N 19810111 19810111 Y 19810111;
WITH T AS ( SELECT '19810101' DAT, 'Y' YN FROM DUAL UNION ALL SELECT '19810103' DAT, 'N' YN FROM DUAL UNION ALL SELECT '19810104' DAT, 'Y' YN FROM DUAL UNION ALL SELECT '19810105' DAT, 'N' YN FROM DUAL UNION ALL SELECT '19810106' DAT, 'N' YN FROM DUAL UNION ALL SELECT '19810107' DAT, 'N' YN FROM DUAL UNION ALL SELECT '19810108' DAT, 'N' YN FROM DUAL UNION ALL SELECT '19810109' DAT, 'N' YN FROM DUAL UNION ALL SELECT '19810111' DAT, 'Y' YN FROM DUAL UNION ALL SELECT '19810112' DAT, 'N' YN FROM DUAL ) SELECT DAT, YN, GRP, MAX( DAT ) OVER( PARTITION BY GRP ) A_DAT FROM ( SELECT DAT, YN, COUNT( DECODE( YN, 'Y', 1 ) ) OVER( ORDER BY DAT DESC ) GRP FROM T ) ORDER BY DAT ; |