site_id | start_date | end_date
1 | oct 1, 08 | oct 2, 08
1 | oct 2, 08 | oct 3, 08
...
1 | oct 30, 08 | oct 31, 08
2 | oct 1, 08 | oct 2, 08
2 | oct 2, 08 | oct 3, 08
...
2 | oct 30, 08 | oct 31, 08
I have a table that contains 1 record per site per day of the month (per month of the year). I need to be able to determine if a site for a given month has at least 15 contiguous records, and I need to know the start and end date of that series of contiguous days. I can do this in a stored procedure, but I was hoping this could be accomplished in a single query. I am dealing with a fairly large dataset, at least 30 million records per month.
Example Results:
site_id | contiguous_start_date | contiguous_end_date
1 | oct 5, 2008 | oct 20, 2008
2 | oct 10 | oct 30, 2008
3 | oct 1 | oct 31, 2008
thanks for your help!
Here is an example of how to do such a query:
And then the query:
And the results:
Regards,
Rob.