select 한 결과가 아래 표와 같이 나옵니다.
......
이 결과를 한줄로
----------------------------------------------
월요일(1~3, 7~8) 수요일(2~3, 9)
----------------------------------------------
이렇게 표현할수 있을까요?
WITH t(day, val) AS(
WITH t AS ( SELECT '월요일' dy, 1 sq FROM dual UNION ALL SELECT '월요일', 2 FROM dual UNION ALL SELECT '월요일', 3 FROM dual UNION ALL SELECT '월요일', 7 FROM dual UNION ALL SELECT '월요일', 8 FROM dual UNION ALL SELECT '수요일', 2 FROM dual UNION ALL SELECT '수요일', 3 FROM dual UNION ALL SELECT '수요일', 9 FROM dual ) SELECT SUBSTR( XMLAGG(XMLELEMENT(z,' ',dy,'(',y,')')ORDER BY d).EXTRACT('//text()') , 2) z FROM (SELECT dy , INSTR('월화수목금토일', SUBSTR(dy, 1, 1)) d , SUBSTR( XMLAGG(XMLELEMENT(y,', ',x)ORDER BY grp).EXTRACT('//text()') , 3) y FROM (SELECT dy, grp , MIN(sq)||DECODE(COUNT(*), 1, '', '~'||MAX(sq)) x FROM (SELECT dy, sq , sq - ROW_NUMBER() OVER(PARTITION BY dy ORDER BY sq) grp FROM t ) GROUP BY dy, grp ) GROUP BY dy ) ;