title: SQL Count of rows in a group in a sequence
body: <p>I apologise for the title of the question, it isn't very clear, but I can't think of a better way of describing it in words, the data should speak for itself.</p>
  <p>I have a table of data where I need to know the count of rows that are the same depending on a value, but also taking into account the sequence they are currently in. The table is much larger than this, but these are the columns which are relevant.</p>
  <pre><code>Id    | MinCode      | MaxCode      | ExpectedResult
  ----------------------------------------------------
  1     | 00001.000001 | 00001.000001 | 2
  2     | 00001.000001 | 00001.000002 | 2
  3     | 00002.00001a | 00002.00001a | 3
  4     | 00002.00001a | 00002.00001b | 3
  5     | 00002.00001a | 00002.00001c | 3
  6     | 00002.000002 | 00002.000002 | 1
  7     | 00002.00003a | 00002.00003a | 2
  8     | 00002.00003a | 00002.00003b | 2
  9     | 00002.000002 | 00002.000004 | 1
  10    | 00003.000001 | 00003.000001 | 1
  </code></pre>
  <p>Note: Id is also the order in this example, I just didn't see the point of an extra column with the same data.</p>
  <p>I have tried several versions using <code>COUNT</code>, <code>ROW_NUMBER/RANK</code>, <code>PARTITION</code> and <code>GROUP BY</code> without getting the ExpectedResult values. The issue is with Ids 6 and 9 as my ExpectedResult value always combines them to produce a 2 which I partially understand as these functions don't take into account the ordering of the data. I believe I'm close, but my T-SQL is pretty rusty these days!</p>
  <p>I know I could get this value with processing this data set through a <code>CURSOR</code>, but I'd like to avoid that.</p>