title: subtract values of two rows and inserting it into a new column (not subsequent rows)
body: <p>relevant to my previous question here: <a href="https://stackoverflow.com/questions/15853354/how-to-insert-subtract-of-each-two-subsequent-rows-and-inserting-it-into-a-new-c/15854174?noredirect=1#comment22590607_15854174">how to insert subtract of each two subsequent rows and inserting it into a new column</a></p>
  
  <p>I have another question. In the following table; I want to calculate the amount of time that have passed from each user's last winning in a competition. in fact I should subtract the last winning date from current date. (place=1) is indicative of winning.</p>
  
  <p>the current table:</p>
  
  <p><a href="http://www.8pic.ir/images/75206897877200828586.jpg" rel="nofollow noreferrer">http://www.8pic.ir/images/75206897877200828586.jpg</a></p>
  
  <p>the result that I want:</p>
  
  <p><a href="http://www.8pic.ir/images/78832309907063712878.jpg" rel="nofollow noreferrer">http://www.8pic.ir/images/78832309907063712878.jpg</a></p>
  
  <p>I wrote the following query for this question (according to the answer that I got for my previous question <a href="https://stackoverflow.com/questions/15853354/how-to-insert-subtract-of-each-two-subsequent-rows-and-inserting-it-into-a-new-c/15854174?noredirect=1#comment22590607_15854174">here</a>) ! but the problem is that I get many duplicate rows! I have only 4000 rows, but when I run this query I get 40,000 rows! what is the problem! would you please help me. and also I get negative value for the users that have not won before. I want these fields be NULL.</p>
  
  <pre><code>;WITH [cte15853354] AS
   (
      SELECT 
          [user-name],
          [submissions],
          [date],
          [place],
          [recency],
          ROW_NUMBER() OVER (ORDER BY [user-name], [date] DESC) AS [ROWNUMBER]
      FROM dbo.[top-design1]
   )
  SELECT 
      t.[user-name],
      t.[submissions],
      t.[date],
      t.[place],
      t.[recency],
      DATEDIFF(DAY, ISNULL(k.[date],t.[date]),t.[date]) AS [win-recency]
  INTO dbo.[top-design2]
  FROM [cte15853354] t
  LEFT JOIN [cte15853354] k
      ON k.[user-name] = t.[user-name] 
       where k.[place]=1 
      ORDER BY t.[user-name], t.[date] DESC
  </code></pre>