title: How to return a incremental group number per group in SQL
body: <p>I would like create a data query in SQL to incrementally number groups of rows, grouped on a common datetime and keep the "group numbers" incrementing on the next datetime and so on. These "group numbers" must not reset for each group as I have seen when using the partition by statement. Here is my sample data:</p>
  
  <pre><code>ts_DateTime          |ID   |Value|RowFilter|RequiredResult
  --------------------------
  2013/01/09 09:23:16  |8009 |0    |1        |1
  2013/01/09 09:23:16  |8010 |0    |2        |1
  2013/01/09 09:23:16  |8026 |0    |3        |1
  
  2013/01/09 09:23:22  |8026 |0    |1        |2
  
  2013/01/09 09:23:28  |8009 |0    |1        |3
  2013/01/09 09:23:28  |8010 |0    |2        |3
  2013/01/09 09:23:28  |8026 |0    |3        |3
  
  2013/01/09 09:27:03  |8009 |0    |1        |4
  2013/01/09 09:27:03  |8010 |0    |2        |4
  2013/01/09 09:27:03  |8026 |0    |3        |4
  
  2013/01/09 09:27:09  |8009 |0    |1        |5
  2013/01/09 09:27:09  |8010 |0    |2        |5
  2013/01/09 09:27:09  |8026 |0    |3        |5
  
  2013/01/09 09:27:15  |8009 |0    |1        |6
  2013/01/09 09:27:15  |8010 |0    |2        |6
  2013/01/09 09:27:15  |8026 |0    |3        |6
  
  
  </code></pre>
  
  <p>The query I am using to get these results is :</p>
  
  <pre><code>select hl.ts_DateTime,  hl.Tagname as [ID],  hl.TagValue as [Value],
  ROW_NUMBER() OVER (PARTITION BY hl.ts_datetime ORDER BY hl.tagname) AS RowFilter
  from Table1 hl
  </code></pre>
  
  <p>So basically, looking at the RowFilter column, I am getting a unique ROW number per <code>ts_DateTime</code> partition. What I actually need is that for each <code>ts_DateTime</code> partition the RowFilter column should look like the Required result column.</p>