sql >> Database >  >> RDS >> Oracle

ORACLE SQL Bereik van uren

Ik neem aan dat je je tijdnotatie hebt geconverteerd naar hh24:mi

misschien kan dit helpen:

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'
  ;

of je kunt between . gebruiken om het te controleren start_hour of end_hour ligt tussen de waarden

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 hier



  1. Hoe krijg ik het laatste werknemersrecord in Oracle?

  2. Hoe records in te voegen in variabelen van cte in orakel?

  3. Tel cumulatief totaal in Postgresql

  4. PHP-script maakt geen verbinding met database?