I have a table that looks like this:
| ID | Date | Transition |
|---|---|---|
| 45 | 01/Jan/09 | 1 |
| 23 | 08/Jan/09 | 1 |
| 12 | 02/Feb/09 | 1 |
| 77 | 14/Feb/09 | 0 |
| 39 | 20/Feb/09 | 1 |
| 33 | 02/Mar/09 | 1 |
I would like a query that returns a running total of the "somedate" column, BUT I want to ignore the transitions from where it goes from "0" to "1" or "0" to "0". (IE: the time between ID: 77 and ID: 39 should not be calculated in the running total). The other transitions ("1" to "0", "1" to "1") should counted as usual.
I want my table to look something like this:
| ID | Date | Running_Total |
|---|---|---|
| 45 | 01/Jan/09 | 0 |
| 23 | 08/Jan/09 | timeDiff(Jan1, Jan8) |
| 12 | 02/Feb/09 | timeDiff(Jan1, Jan8) + timediff(Jan8, Feb2) |
| 77 | 14/Feb/09 | timeDiff(Jan1, Jan8) + timediff(Jan8, Feb2) + timeDiff(Feb2, Feb14) |
| 39 | 20/Feb/09 | timeDiff(Jan1, Jan8) + timediff(Jan8, Feb2) + timeDiff(Feb2, Feb14) + 0 |
| 33 | 02/Mar/09 | timeDiff(Jan1, Jan8) + timediff(Jan8, Feb2) + timeDiff(Feb2, Feb14) + 0 + timeDiff(Feb20, Mar2) |
Something like that. I know how to calculate the accumulated cost, but I was wondering if there's any way to get the accumulated cost but also filter it out based on "transitions".
I've tried looking online and on other window functions, but not sure how to incoporate the fact of "looking" at future rows and comparing to initial row with window function.
Any help would be greatly appreciated.
The above adds the difference between
currentandpreviousto a grand total (in terms ofTIMEDIFF) whereprevious.Transitionis 1 and there is no item betweenpreviousandcurrent.