A B
111 222
222 333
333 444
555 666
666 777
777 888
결과
111 444
555 777
이렇게 출력하고 싶습니다
WITH t AS ( SELECT 111 a, 222 b FROM dual UNION ALL SELECT 222, 333 FROM dual UNION ALL SELECT 333, 444 FROM dual UNION ALL SELECT 555, 666 FROM dual UNION ALL SELECT 666, 777 FROM dual UNION ALL SELECT 777, 888 FROM dual ) SELECT MIN(a) a , MAX(b) b FROM (SELECT a, b , SUM(flag) OVER(ORDER BY a) grp FROM (SELECT a, b , DECODE(a, LAG(b) OVER(ORDER BY a), 0, 1) flag FROM t ) ) GROUP BY grp ORDER BY grp ;