sql >> Database >  >> RDS >> Oracle

Groeperen op waarden die op volgorde staan

Je kunt Aketi Jyuuzou's techniek genaamd Tabibitosan hier gebruiken:

SQL> create table mytable (id,chequeno)
  2  as
  3  select 1, 15 from dual union all
  4  select 2, 19 from dual union all
  5  select 3, 20 from dual union all
  6  select 4, 35 from dual union all
  7  select 5, 16 from dual
  8  /

Table created.

SQL> with tabibitosan as
  2  ( select chequeno
  3         , chequeno - row_number() over (order by chequeno) grp
  4      from mytable
  5  )
  6  select row_number() over (order by grp) "row"
  7       , min(chequeno) "from"
  8       , max(chequeno) "to"
  9    from tabibitosan
 10   group by grp
 11  /

       row       from         to
---------- ---------- ----------
         1         15         16
         2         19         20
         3         35         35

3 rows selected.

Met vriendelijke groet,
Rob.



  1. Hoe de TO_BASE64()-functie werkt in MySQL

  2. Easysoft ODBC-stuurprogramma's en de ODBCINST-bibliotheek

  3. Draaien met SQL Server 2000

  4. MariaDB RONDE() vs TRUNCATE()