Hi, i'm wondering if there exists SQL code to determine the date difference between successive rows. For example, a query I have would return something like this: (where VAL > 500 but notice the GAP that says there are 14 entries that were not included ie, VAL <= 500) If I want to determine the amount of time that VAL was > 50, i'd take the date difference from ID 81 and 80 and 96 and 95 (out of simplicity I won't count any time within the gap)
ID NAME VAL DATE
80 T5212057 502 1/8/94 18:22
81 T5212057 506 1/8/94 18:25
> gap <
95 T5212057 501 1/8/94 19:43
96 T5212057 504 1/8/94 19:47
I understand there is a datediff() function that can do this, but is it possible to combine this with sql to do it on the fly (when no gap exists) and then sum the total up... Or even, just do the datediff in hours on the fly then I can sum them up later. If not, I can do this in excel, i'm just trying to save a step
Thanks.
Frank
ID NAME VAL DATE
80 T5212057 502 1/8/94 18:22
81 T5212057 506 1/8/94 18:25
> gap <
95 T5212057 501 1/8/94 19:43
96 T5212057 504 1/8/94 19:47
I understand there is a datediff() function that can do this, but is it possible to combine this with sql to do it on the fly (when no gap exists) and then sum the total up... Or even, just do the datediff in hours on the fly then I can sum them up later. If not, I can do this in excel, i'm just trying to save a step
Thanks.
Frank