Getting clusters of rows close together in time
Posted
by Mike
on Stack Overflow
See other posts from Stack Overflow
or by Mike
Published on 2010-04-21T01:07:04Z
Indexed on
2010/04/21
1:13 UTC
Read the original article
Hit count: 369
I have a table basically like so
ID | ItemID | Start | End |
---------------------------------------------------------------
1 234 10/20/09 8:34:22 10/20/09 8:35:10
2 274 10/20/09 8:35:30 10/20/09 8:36:27
3 272 10/21/09 12:15:00 10/21/09 12:17:00
4 112 10/21/09 12:20:14 10/21/09 12:21:21
5 15 10/21/09 12:22:39 10/21/09 12:24:15
There are two "clusters" of entries here, 1-2 and 3-5 separated by a gap in time, specifically > 30 minutes is what I'm interested in.
What I would like is the first and last rows of the cluster of entries. This is fairly easy to achieve by retrieving all the rows and looping through them in order of start time, but I'd like to have it in SQL if possible.
I'm using SQL Server 2008, thanks.
© Stack Overflow or respective owner