RATE THIS ANSWER
0
Click to Vote:
0
0
By looking at your query,
I will assume you are doing this on an Oracle database.
You are getting more days because you are calculating the total downtime for each record, even when some records comprise dates outside your desired range.
You will have to check the end time for the records, and when the end_time is greater than the last day you want to include in the report, you should calculate the downtime based on that day, and not on the end_time column. And something similar needs to be done with the start times.
A combination of the DECODE and SIGN functions could help.
The downtime calculation should be something like this:
sum(decode(sign(a.end_time-to_date('30-MAY-09')),1,'30-MAY-2009',a.end_time) - decode(sign(a.start_time-to_date('24-MAY-09')),-1,'24-MAY-2009',a.start_time)) Also, filtering the results using the start_time only will not work.
You need a condition similar to this:
a.start_time <= '30-MAY-09' AND a.end_time >= '24-MAY-09'
Last Answered:
Sep 29 2009 10:35 PM GMT by Carlosdl 
29820 pts.