Question : Count consecutive numbers and the attach back to original dataset

Follow up to previous question:
Original Question...
I have a dataset where I need to count the occurance of consecutive numbers.  The challenge is that the same number can show up throughout the dataset, so you can't do a simple group by and count.  Each row has a unique row ID that increments by 1.  

It is simple to do in Excel with row+1 formulas, but in a database it has been tuff.  I have been able to get close by joining the table to itself on the Unique ID +/- 1 to get the previous and next day values in one record, however that does not solve my objective of getting a count of consecutive values when the same value can show up more than once in separate places.

Here is a subset of the data:
ID      COBDate      Name      Value
821902      11/27/06      Series1      7.008571667
821903      11/28/06      Series1      7.008571667
821904      11/29/06      Series1      7.008571667
821905      11/30/06      Series1      7.007347143
821906      12/01/06      Series1      7.008571667
821907      12/04/06      Series1      7.008571667
821908      12/05/06      Series1      7.008571667

should result in:
Count 1: 7.008571667 = 3
Count 2: 7.007347143 = 1
Count 3: 7.008571667 = 3

The accepted solution..
SELECT First(Value) As Val, Count(*) As N
FROM
  (SELECT
     A.ID,
     A.Value,
     (Select Top 1 ID From YourSample B
      Where A.Value<>B.Value And B.ID      Order by ID Desc
     ) AS grp
    FROM YourSample A
  ) As C
GROUP BY grp

New Requirement... Attach the counts and a unique group ID back to the original datase.  The group ID can be something like the first ID in the consecutive occurance.  Looks something like this:
ID      COBDate      Name      Value                   GroupID      Count
821936      11/27/06      Series2      7.008571667             821936      3
821937      11/28/06      Series2      7.008571667                   821936      3
821938      11/29/06      Series2      7.008571667                   821936      3
821939      11/30/06      Series2      7.007347143                   821939      1
821940      12/01/06      Series2      7.008571667                   821940      3
821941      12/04/06      Series2      7.008571667                   821940      3
821942      12/05/06      Series2      7.008571667             821940      3


Attached is an excel file to import to Access for testing.

Answer : Count consecutive numbers and the attach back to original dataset

(°v°)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
SELECT *
FROM
  (SELECT
     A.*,
     (Select Top 1 ID From YourSample B
      Where B.ID > All (
        Select ID From YourSample C
        Where C.Value<>A.Value And C.ID All (
           Select ID From YourSample C
           Where C.Value<>A.Value And C.ID
           
Random Solutions  
 
programming4us programming4us