sql >> Databasteknik >  >> RDS >> Oracle

ORACLE SQL Tidsintervall

Jag antar att du har konverterat ditt tidsformat till hh24:mi

kanske detta kan hjälpa:

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 så kan du använda between för att kontrollera det start_hour eller end_hour är mellan värdena

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<>fiol här



  1. ClusterControl - Advanced Backup Management - mariabackup del II

  2. Hur returnerar jag månadens vecka i MySQL?

  3. Tabellindex för text[]-matriskolumner

  4. Java - datum sparat som dagen innan