I have a table that defines time intervals.
_______________________________
| id | description | start_date |
|____|_____________|____________|
| 1 | First | NULL |
| 3 | Third | 2009-12-18 |
| 5 | Second | 2009-10-02 |
| 4 | Last | 2009-12-31 |
|____|_____________|____________|
It stores only the start date, the end date is a day before next date that follows.
I would like to have the next result:
____________________________________________
| id | description | start_date | end_date |
|____|_____________|____________|____________|
| 1 | First | NULL | 2009-10-01 |
| 5 | Second | 2009-10-02 | 2009-12-17 |
| 3 | Third | 2009-12-18 | 2009-12-30 |
| 4 | Last | 2009-12-31 | NULL |
|____|_____________|____________|____________|
How should I write this query, since a row contains values from other rows?
(I think MySQL function DATE_SUB
could be useful.)