Oracle
 sql >> Baza danych >  >> RDS >> Oracle

Uzyskaj kopertę.tj. nakładające się okresy czasu

Wypróbuj też ten. Przetestowałem to najlepiej, jak mogłem, wierzę, że obejmuje wszystkie możliwości, w tym łączenie sąsiednich interwałów (10:15 do 10:30 i 10:30 do 10:40 są połączone w jeden interwał, 10:15 do 10:40 ). Powinien być również dość szybki, nie zużywa dużo.

with m as
        (
         select ip_address, start_time,
                   max(stop_time) over (partition by ip_address order by start_time 
                             rows between unbounded preceding and 1 preceding) as m_time
         from ip_sessions
         union all
         select ip_address, NULL, max(stop_time) from ip_sessions group by ip_address
        ),
     n as
        (
         select ip_address, start_time, m_time 
         from m 
         where start_time > m_time or start_time is null or m_time is null
        ),
     f as
        (
         select ip_address, start_time,
            lead(m_time) over (partition by ip_address order by start_time) as stop_time
         from n
        )
select * from f where start_time is not null
/


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. NEW_TIME() Funkcja w Oracle

  2. Oracle 12c IDENTYFIKOWANE WARTOŚCIAMI

  3. Jak używać ora_hash w kolumnie typu danych xmltype

  4. Funkcja ATAN2() w Oracle

  5. java.sql.SQLException:- ORA-01000:przekroczono maksymalną liczbę otwartych kursorów