Hello and thanks in advance for any help, I work in the Oracle SQL environment.
My problem is specified in this picture:
Input:
I have date intervals belonging for a customer which never go beyond the scope of one month. I need to connect those intervals where the end of first interval is the end of a month and the next interval starts the first day of the next month (that is the only way they connect).
In the column "days between" it is already obvious, that when there is a start of a new interval the number is higher than 1 and when the current row belongs to an interval there is 1.
Some specifics:
- For 1 user there can be more than two intervals, in the example there is one user with three intervals
- The intervals can be several months long = occupying several rows.
- The spacing between intervals can be also several months long.
Output:
Specific example of the desirable output is in the attached picture. Simply - I want for each row to be specified when does the whole interval, in which the row interval is included, start and end.
Data:
ID Start date End date Last start date Last end date Days between
12 21.03.2016 31.03.2016 1
12 01.04.2016 04.04.2016 21.03.2016 31.03.2016 1
12 28.04.2016 30.04.2016 01.04.2016 04.04.2016 24
12 01.05.2016 20.05.2016 28.04.2016 30.04.2016 1
12 06.06.2016 30.06.2016 01.05.2016 20.05.2016 17
12 01.07.2016 13.07.2016 06.06.2016 30.06.2016 1