Re: Query for Days Between Dates in Records
Posted in 1997
In article <33b2c4fa.24953621@news.interport.net>,
Alan Z. Scharf <ascharf@grapevines.com> 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
How about this:-
create temp table a_table ( a_date date ) ;
insert into a_table values ( '1/1/97' ) ;
insert into a_table values ( '3/15/97' ) ;
insert into a_table values ( '4/17/97' ) ;
insert into a_table values ( '5/14/97' ) ;
select a_table1.a_date, a_table1.a_date - max(a_table2.a_date)
from a_table a_table1, outer a_table a_table2
where a_table1.a_date > a_table2.a_date
group by 1
order by 1
which returns:-
a_date (expression)
01/01/1997
03/15/1997 73
04/17/1997 33
05/14/1997 27
- Paul (his opinions only, etc)