sql - Oracle range and subquery -


i have table that trying query against , i'm not sure how go it.

table name: schedule

  • user_id
  • startdate
  • enddate
  • sequencyid

the situation have number of rows user_id = 0. represents open schedule can claim. if schedule gets claimed gets assigned specific user id. here tricky part comes in. trying pick user , display schedule times don't overlap have been accepted or been scheduled.

here have far

select *    schedule   user_id = 123456; 

that gets me ranges of times person has accepted

select *    schedule   user_id = 0; 

this gets me schedule rows available. i'm not quite sure how combine them such final result list of schedule elements whos user_id =0 , startdate / enddate don't exist between startdate , endate ones assigned user.

i think

select *    schedule   user_id = 0     , (loop through schedule rows testing             (startdate < loopstartdate , enddate < loopstartdate) ||             (startdate > loopenddate) 

the i'm struggling with. ideas? if @ least point me in right direction mechanism i'd use begin solve type of problem awesome.

select a.* schedule user_id = 0   , not exists (     select null       schedule b       b.user_id = 123456         , b.start_date <= a.end_date         , b.end_date >= a.start_date   ) 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -