Hi everyone! I am pretty much new to Oracle it has only been 3 months or so I guess and I have a bit of a problem now. I'm running a query which will display the downtime of a machine. It will display the Start/End Time and its difference. The maching runs in two shifts, Shift A being 6:00 AM to 6:00 PM and Shift B on 6:00 PM to 6:00 AM. Below is a sample resulting set of my query:
___________________________________________________________________________________________
Shift StartDateTime EndDateTime DifferenceInMinutes
B 09/25/2012 17:38:40 09/25/2012 19:12:26 93.7667
B 09/25/2012 19:12:26 09/25/2012 19:25:03 12.6167
B 09/25/2012 19:25:03 09/26/2012 05:55:08 630.0833
A 09/26/2012 05:55:08 09/26/2012 09:19:55 24.8
___________________________________________________________________________________________
The total in DifferenceInMinutes should always be 720 per shift. What I did is that on each start of a shift, it'll be 6:00 AM for Shift A and 18:00 on Shift B. I used Case When to be able to do this. Below will be another example of the resulting set:
___________________________________________________________________________________________
Shift StartDateTime EndDateTime DifferenceInMinutes
B 09/25/2012 18:00:00 09/25/2012 19:12:26 72.43333
B 09/25/2012 19:12:26 09/25/2012 19:25:03 12.6167
B 09/25/2012 19:25:03 09/26/2012 05:55:08 630.0833
A 09/26/2012 06:00:00 09/26/2012 09:19:55 199.9167
___________________________________________________________________________________________
Now my only problem is the EndDateTime, the last item on a shift should always end at 18:00 for Shift A and 6:00 for Shift B. I want to achieve something like below:
___________________________________________________________________________________________
Shift StartDateTime EndDateTime DifferenceInMinutes
B 09/25/2012 18:00:00 09/25/2012 19:12:26 72.43333
B 09/25/2012 19:12:26 09/25/2012 19:25:03 12.6167
B 09/25/2012 19:25:03 09/26/2012 06:00:00 634.95
A 09/26/2012 06:00:00 09/26/2012 09:19:55 199.9167
___________________________________________________________________________________________
I must admit that I do not know how to use Case When like what I have done on StartDateTime so I'm really hoping that there is a way for this. Thanks guys. I hope I made sense here. Cheers :)