SQL> SELECT b.fphm, MIN (b.kshm) Start_HM, MAX (b.kshm) End_HM2 FROM (SELECT a.*, TO_NUMBER (a.kshm - ROWNUM) cc3 FROM (SELECT *4 FROM t5 ORDER BY fphm, kshm) a) b6 GROUP BY b.fphm, b.cc7 /FPHM START_HM END_HM---------- -------- --------2013 00000120 000001222013 00000124 000001252014 00000001 000000052014 00000007 00000009