sql >> Database teknologi >  >> RDS >> Oracle

ORACLE SQL Timeinterval

Jeg går ud fra, at du har konverteret dit tidsformat til hh24:mi

måske dette kunne hjælpe:

with tab as(
select 'date1' as dat,  '09:00' as  start_hour, '09:30' as end_hour from dual union all
select 'date1' as dat,  '10:30' as  start_hour, '11:30' as end_hour from dual union all
select 'date1' as dat,  '13:00' as  start_hour, '15:00' as end_hour from dual 
)
SELECT COUNT(*)
  FROM   tab
  WHERE  start_hour <= '09:10' --:new_end_hour
  AND    end_hour   >= '07:00' --:new_start_hour
  AND    dat = 'date1'
  ;

eller du kan bruge between for at kontrollere det start_hour eller end_hour er mellem værdierne

with tab as(
select 'date1' as dat,  '09:00' as  start_hour, '09:30' as end_hour from dual union all
select 'date1' as dat,  '10:30' as  start_hour, '11:30' as end_hour from dual union all
select 'date1' as dat,  '13:00' as  start_hour, '15:00' as end_hour from dual 
)
SELECT COUNT(*)
  FROM   tab
  WHERE  ('09:00' between start_hour and end_hour
  or    '09:10' between start_hour and end_hour
  )
  AND    dat = 'date1'
  ;

db<>fiddle her



  1. Brug af Geekbench 3 til at evaluere databaseserverens ydeevne

  2. Hvordan sender man SSIS-variabler i ODBC SQLCommand-udtryk?

  3. PG gem vil ikke installeres i Rails app:Gem::Ext::BuildError:FEJL:Kunne ikke bygge gem native extension

  4. At få jQuery-autofuldførelse til at fungere med PHP-kilde