Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Calculating time differences

user517674Sep 24 2008 — edited Sep 27 2008
I am having issues trying to calculate these values:

TABLEA


ID SCHD_FROM SCHD_TO UNSCHD_FROM UNSCHD_TO

123 7/1/2008 7:15:00 AM 7/1/2008 12:30:00 PM
123 7/1/2008 12:30:00 PM 7/1/2008 5:00:00 PM
234 9/1/2008 7:00:00 AM 9/1/2008 1:00:00 PM 9/1/2008 9:00:00 AM 9/1/2008 11:00:00 AM



TABLE B


ID START END

123 7/1/2008 11:30:00 AM 7/1/2008 5:30:00 PM
234 9/1/2008 8:00:00 AM 9/1/2008 1:00:00 PM


Output I want is:


ID IN_MINS OUT_MINS

123 330 30
234 180 120

For row 1 in output:

In_Mins ---------> I want to compare my tableB row with the 2 rows in table A and see how many minutes of start and end FALL between schd_from and schd_end
Out_Mins -------> I want to compare my tableB row with the 2 rows in table A and see how many minutes of start and end DOES NOT FALL between schd_from and schd_end

For row 2 in output:

In_Mins ---------> I want to compare my tableB row with the 2 rows in table A and see how many minutes of start and end FALL between schd_from and schd_end AND see if there is any unschd_from time in it, if there is then I need to subtract it from the total.
Out_Mins -------->Any start and end time that falls between unschd_from and unschd_to should go to out_mins

I am looking for an approach as to how to proceed with it.

Thank you
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 25 2008
Added on Sep 24 2008
17 comments
658 views