Re: SQL Query (Joining the table to itself)
Date: 1996/02/11
Message-ID: <4fkm68$2us_at_newsbf02.news.aol.com>#1/1
In article <3108CD7D.4C1F_at_power.it-riga.lv>, Ivars Grinbergs <ivars_at_power.it-riga.lv> writes:
>Source data:
>> frequency Thru_Date Status
>> ------------------------------------------
>> Monthly 01-JAN-96 C
>> Monthly 01-FEB-96 I
>> Monthly 01-MAR-96 I
>> Monthly 01-APR-96 I
>> Monthly 01-MAY-96 I
Result needed:
>> Frequency From_Date To_Date
>> ----------------------------------------------
>> Monthly 01-FEB-96 01-MAR-96
>> Monthly 01-MAR-96 01-APR-96
>> Monthly 01-APR-96 01-MAY-96
>To get results exactly above, the following query could be used:
>
>SELECT frequency, from_date, add_months(from_date,1) to_date
>FROM your_table
>WHERE from_date between '01-FEB-96' and '01-APR-96';
>
>Sincerely
>Ivars Grinbergs
I think that it would be better to use:
SELECT frequency,add_months(thru_date,-1) "From_Date", thru_date "To_Date" where thru_date between to_date('01-MAR-96','dd-mon-yy') andto_date('01-MAY-96','dd-mon-yy');
since thru_date implies the end of the range, not the beginning.
from your_table
where thru_date between
Received on Sun Feb 11 1996 - 00:00:00 CET