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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 group consecutive records

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2007-02-14 : 08:33:02
Rameez writes "I'm looking for a way to group consecutive records. I have a table called Data with two fields; a primary key 'Time' which is a datetime and 'Value' which is a decimal. See below:

----------------------------------------
Time | Value |
----------------------------------------
2/6/2007 02:05:00.333 3.8
2/6/2007 02:10:00.333 3.8
2/6/2007 02:15:00.333 9.0
2/6/2007 02:20:00.333 9.0
2/6/2007 02:25:00.333 9.0
2/6/2007 02:30:00.333 3.8
2/6/2007 02:35:00.333 3.8

I want to be able to group by min(Time) and Value, but only those records that are consecutive. So from the data set i supplied i should be able to obtain the following data:

----------------------------------------
Time | Value |
----------------------------------------
2/6/2007 02:05:00.333 3.8
2/6/2007 02:15:00.333 9.0
2/6/2007 02:30:00.333 3.8

Any ideas? I've been trying to solve this for ages."

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-14 : 08:58:20
answered here http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=78871


KH

Go to Top of Page
   

- Advertisement -