I'm concerned that we may not have a clear picture of how a group is defined. I only say this because, depending on some unstated conditions, the dates above will either form one giant single group, or 3 groups where one group dominates the set.
Missing grouping conditions?
Does this 15 day rule cascade? If a record
Y
starts 10 days after another recordX
, and then there is another recordZ
started 10 days after that, then does this form one group of three recordsX,Y,Z
, or two groups each containing two recordsX,Y
andY,Z
? I made the assumption that the 15 day rules cascades to form larger groups.Are the dates inclusive? For example, if one record has a start date and then a dead date many months later, do all days within that range get merged into the group? I treat both possibilities in my quick analysis below.
Potential Groupings
So, if we begin with id 7714
, we see that the start date is 1/27. Clearly, the next entry 7882
starting on 1/28 falls in this group. Notice however that 7882
ends on 5/15, so anything which starts within 15 days of 5/15 must be added to the group.
Thus, 19690
through 21210
get added to the group, which via cascading leads to 21918
being subsequently added to the group. The cascading has consumed nearly all entries in the set. Call this GROUP A
.
If, however, the grouping is date inclusive as well, all entries from 13190
up to 17124
must also belong to GROUP A
, and now all ids are in a single group.
If the dates from GROUP A
aren't inclusive, but actually strictly adhere to the '15 day after' rule with cascading, then instead you would have a second group composed of 13190
through 14020
, and a third group with a single entry, 17124
.
Essentially, my question is, do any of these match your intended grouping, or is there some other information we're missing in the group definition? I'm sorry for such a long-winded answer, but it doesn't appear that your tentative requested output meets your grouping definition.
With clarifications, I'm sure that we can sort this problem out.