Here's a simple programmatic method (careful, I haven't tested it). declare v_activity_count number := 0; begin for rec in ( select start_time event_time, 'start' event_type from some_table union select end_time event_time, 'end' event_type from some_table order by 1 ) loop if(rec.event_type = 'start') then v_activity_count:= v_activity_count + 1; else v_activity_count:= v_activity_count - 1; end if if(v_activity_count = 1) then -- One activity elseif(v_activity_count > 1) then -- Overlapping activities else -- Nothing going on end if; end loop; end;
Regards David Lord -----Original Message----- [mailto:[EMAIL PROTECTED] Sent: 31 October 2003 18:25 To: Multiple recipients of list ORACLE-L I was wondering if anyone had the need to find overlapping time periods and how to identify them efficiently. Here is the scenario: Elapsed minutes refer to the actual "clock" time either spent on a given task. Thus an activity that started at 9:00 am and finished at 11:00 am on the same day is said to have 120 elapsed minutes. If one task overlaps another (either completely or partially with another task), then the tasks are said to be "multitasked". In that case the system will store the portion of the elapsed time that was multitasked as "elapsed multitask minutes" and the portion of the time that was not overlapped as "elapsed single minutes". In addition, for the portion of time that two or more activities were simultaneously taking place; their time will be divided by the number of simultaneous activities and stored as "prorated multi minutes". The sum of Elapsed Single Minutes and Prorated Minutes will equal the actual clock time that a vehicle was active. The following example should help to illustrate these concepts. In the table below a list of fictitious activities for a vehicle are shown in addition to how the time is allocated to the various measures: Activity Start Time End Time Elapsed Minutes Elapsed Multitask Minutes Elapsed Single Minutes Prorated Multi Minutes Prorated Minutes 1 10:00 12:00 120 60 60 25 85 3 11:00 13:00 120 120 0 55 55 4 11:30 13:30 120 90 30 40 70 7 13:30 16:00 150 0 150 0 150 Totals 510 270 240 120 360 The vehicle was active from 10:00 to 16:00, a total of 6 hours (360 minutes) which is equal to the total of Prorated Minutes. The vehicle performed 8 ½ hours (510 minutes) of work during that 6-hour time span. This can be arrived at by adding the total of Elapsed Multitask Minutes (270) + the total of Elapsed Single Minutes (240). *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** This e-mail and its attachments are intended for the author's addressee only and may be confidential. If they have come to you in error you must take no action based on them, nor must you copy or show them to anyone; please reply to this e-mail and highlight the error. Please note that this e-mail has been created in the knowledge that Internet e-mail is not a 100% secure communications medium. We advise that you understand and observe this lack of security when e-mailing us. Steps have been taken to ensure this e-mail and attachments are free from any virus, but advise the recipient to ensure they are actually virus free. The views, opinions and judgments expressed in this message are solely those of the author. The message contents have not been reviewed or approved by Iron Mountain. *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** -- Please see the official ORACLE-L FAQ: http://www.orafaq.net -- Author: Lord David INET: [EMAIL PROTECTED] Fat City Network Services -- 858-538-5051 http://www.fatcity.com San Diego, California -- Mailing list and web hosting services --------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).