I have a subset of entries that look like this:
ID DATE A 2015-09-01 A 2015-10-03 A 2015-10-10 B 2015-09-01 B 2015-09-10 B 2015-10-03 ...
For each identifier, the first minimum date is the first index entry. Now I need to exclude cases within 30 days after the index record, and any record with a date exceeding 30 days will become another index record.
For example, for ID A, 2015-09-01 and 2015-10-03 are both index entries and will be saved since they are more than 30 days apart. 2015-10-10 will be dropped because it is within 30 days after the case of the 2nd index.
For ID B, 2015-09-10 will be discarded and will NOT be indexed, because it is within 30 days after the first record of the index. 2015-10-03 will be retained because it exceeds 30 days of the first index entry and will be considered as the second case of the index.
The result should look like this:
ID DATE A 2015-09-01 A 2015-10-03 B 2015-09-01 B 2015-10-03
How to do this on SQL Server 2012? There is no limit to how many dates an identifier can have, maybe from 1 to 5 or more. I am pretty easy to use SQL, so any help would be greatly appreciated.
source share