Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
PaulVipond
Starting Member
1 Post |
Posted - 2009-02-25 : 05:26:19
|
| Hi All,This is a problem I've come across in a number of different guises. This time I have users carrying out certain activities. E.g. they could be sleeping, reading, snoring, whatever, but each activity is stamped simply with a date / time and the activity type:ActivityDateTime ActivityType30/01/2008 12:34 Sleeping30/01/2008 12:35 Sleeping30/01/2008 12:36 Sleeping30/01/2008 12:40 Snoring30/01/2008 12:41 Snoringetc.The question is, how do I easily identify uninterrupted chains of the same activity, e.g. sleeping. Ideally I'd like it parameterised:"Find me the starting row of a chain at least X in length of activity Y."I've done this before by adding temporary columns for next / previous activities etc, but was wondering if there's an efficient set oriented way of doing this in SQL.Many Thanks |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-25 : 10:05:34
|
| http://www.sqlteam.com/article/detecting-runs-or-streaks-in-your-data |
 |
|
|
|
|
|