title: SQL: create counter for duplicate entries
body: <p>I would like to create an integer counter for duplicate entries on an intermediate table in an import step. Let's say I have a table called <code>FinalTable</code>, which looks like this:</p>
  
  <p><code>FinalTable</code></p>
  
  <pre><code>ID       Date          SameDateCounter
  1003     2012/01/01    NULL
  1004     2012/02/01    NULL
  1005     2012/03/01    1
  1006     2012/03/01    2
  1007     2012/03/01    3
  1008     2012/04/01    1
  1009     2012/04/01    2
  </code></pre>
  
  <p>And has a unique constraint on <code>(Date, SameDateCounter)</code>. In the intermediate step the data is in <code>IntermediateTable</code>, which looks exactly like <code>FinalTable</code> except that it doesn't have any constraints. So the starting point for this problem is here:.</p>
  
  <p><code>IntermediateTable</code>:</p>
  
  <pre><code>ID       Date          SameDateCounter
  1003     2012/01/01    NULL
  1004     2012/02/01    NULL
  1005     2012/03/01    NULL
  1006     2012/03/01    NULL
  1007     2012/03/01    NULL
  1008     2012/04/01    NULL
  1009     2012/04/01    NULL
  </code></pre>
  
  <p>And I need to generate the values for SameDateCounter, starting at one, where the date appears more than once.</p>