title: Is it possible to add a identity to a GROUP BY using SQL?
body: <p>Is it possible to add a identity column to a GROUP BY so that each duplicate has a identity number?</p>
  
  <p>My original data looks like this:</p>
  
  <pre><code>1    AAA  [timestamp]
  2    AAA  [timestamp]
  3    BBB  [timestamp]
  4    CCC  [timestamp]
  5    CCC  [timestamp]
  6    CCC  [timestamp]
  7    DDD  [timestamp]
  8    DDD  [timestamp]
  9    EEE  [timestamp]
  ....
  </code></pre>
  
  <p>And I want to convert it to:</p>
  
  <pre><code>1    AAA   1
  2    AAA   2
  4    CCC   1
  5    CCC   2
  6    CCC   3
  7    DDD   1
  8    DDD   2
  ...
  </code></pre>
  
  <p>The solution was:</p>
  
  <pre><code>CREATE PROCEDURE [dbo].[RankIt]
  AS
  BEGIN
  SET NOCOUNT ON;
  
  SELECT  *, RANK() OVER(PARTITION BY col2 ORDER BY timestamp DESC) AS ranking 
  FROM MYTABLE;
  
  END
  </code></pre>