Have to compare dates of two rows in one table
Input table
COL1| COL2| COL3| COL4
1| A| 1-Jan-07| 6-Feb-08
2| A| 7-Feb-08| 31-Mar-08
3| A| 1-Jan-09| NULL
SQL code to compare COL 4 date (Row 1) with COL 3 date (row 2)
and compare COL 4 date (Row 2) with COL 3 date (row 3)
If COL2 (ROW2) date is equal to COL 3 (ROW 1) + 1 = output Col 4 =A
If COL2 (ROW2) date is equal to COL 3 (ROW 1) + 2 = output Col 4 =R
OUTPUT table
COL1| COL2| COL3| COL4
A| 1-Jan-07|| 6-Feb-08| A
A| 7-Feb-08| 31-Mar-08| O
A| 1-Jan-09| NULL| R