title: how to insert subtract of each two subsequent rows and inserting it into a new column
body: <p>I have a question about writing query in sql.</p>
  
  <p>in the picture 1 I want to subtract row 2 from row1 (in column date) and insert it's result in row1 of new column with the title of Recency. and again subtract row3 from row2 and insert it in row2 of the new column, and so on.</p>
  
  <p><a href="http://www.8pic.ir/images/14490285632526381013.jpg" rel="nofollow noreferrer">picture 1</a>:</p>
  
  <p><img src="https://i.stack.imgur.com/fJHLv.jpg" alt="enter image description here"></p>
  
  <p>in fact I want to calculate the recency of each user's activity. for example in the following picture, I calculated this for one user(manually); I want to do this for all of the users by writing a query in sql.</p>
  
  <p><a href="http://www.8pic.ir/images/38478033832080790150.jpg" rel="nofollow noreferrer">picture 2</a>: </p>
  
  <p><img src="https://i.stack.imgur.com/JwsLf.jpg" alt="enter image description here"></p>
  
  <p>..........................................................................................</p>
  
  <p>and other question:</p>
  
  <p>I also want to calculate the frequency of activity of each user before the current date. I want to calculate frequency for each row. for example for this example, for user abkqz we have:</p>
  
  <pre><code>user name     frequency
  abkqz             4
  abkqz             3
  abkqz             2
  abkqz             1
  abkqz             0
  </code></pre>