Re: Query for Days Between Dates in Records
Posted in 1997
Douglas Wilson — — source: Informix-list mailing list archive (1991-1998)
Alan Z. Scharf wrote:
>
> Is there an SQL query that would give the days between a date in a
> record and the date in the previous record?
>
> For Example:
>
> Date DaysBetween
> 1/1/97 0
> 3/15/97 73
> 4/17/97 33
> 5/14/97 27
This should work for everything but the first record,
and won't work for duplicate dates, if there's a
serial column or something in the same order as the
dates you could adjust it to work for the above exceptions:
select t1.date_col,
(select min(t2.date_col)
from this_table t2
where t1.date_col < t2.date_col)-t1.date_col days_between
from this_table t1
This is not very efficient either. I'd use 4GL or ESQL/C
or somesuch language if there's alot of data.
Good Luck,
Douglas Wilson