Requirement is to Group record of table based on 10 second time interval. Given table
Id DateTime Rank
1 2011-09-27 18:36:15 1
2 2011-09-27 18:36:15 1
3 2011-09-27 18:36:19 1
4 2011-09-27 18:36:23 1
5 2011-09-27 18:36:26 1
6 2011-09-27 18:36:30 1
7 2011-09-27 18:36:32 1
8 2011-09-27 18:36:14 2
9 2011-09-27 18:36:16 2
10 2011-09-27 18:36:35 2
Group Should be like this
Id DateTime Rank GroupRank
1 2011-09-27 18:36:15 1 1
2 2011-09-27 18:36:15 1 1
3 2011-09-27 18:36:19 1 1
4 2011-09-27 18:36:23 1 1
5 2011-09-27 18:36:26 1 2
6 2011-09-27 18:36:30 1 2
7 2011-09-27 18:36:32 1 2
8 2011-09-27 18:36:14 2 3
9 2011-09-27 18:36:16 2 3
10 2011-09-27 18:36:35 2 4
For Rank 1 Minimum time is 18:36:15 and based on that all records between 18:36:15 to 18:36:24 should be in a group and so on.
I want GroupRank in the same table. so it would be something with dense_Rank() Over clause. Can anyone help me to write the query in SQL.