title: Calculate delta(difference of current and previous row) mysql group by specific column
body: <p>I have a table like : session is the name of the table for example
  With columns: Id, sessionDate, user_id</p>
  
  <p>What i need:
  Delta should be a new calculated column</p>
  
  <pre><code>Id | sessionDate          | user_id | Delta in days
  ------------------------------------------------------
  1  | 2011-02-20 00:00:00 |     2    | NULL
  2  | 2011-03-21 00:00:00 |     2    | NULL
  3  | 2011-04-22 00:00:00 |     2    | NULL
  4  | 2011-02-20 00:00:00 |     4    | NULL
  5  | 2011-03-21 00:00:00 |     4    | NULL
  6  | 2011-04-22 00:00:00 |     4    | NULL
  </code></pre>
  
  <p>Delta is the Difference between the timestamps
  What i want is a result for Delta Timestamp (in Days) for the the previous row and the current row grouped by the user_id.</p>
  
  <p>this should be the result:</p>
  
  <pre><code>Id | sessionDate         | user_id | Delta in Days
  ------------------------------------------------------
  1  | 2011-02-20 00:00:00 |     2   | NULL
  2  | 2011-02-21 00:00:00 |     2   | 1
  3  | 2011-02-22 00:00:00 |     2   | 1
  4  | 2011-02-20 00:00:00 |     4   | NULL
  5  | 2011-02-23 00:00:00 |     4   | 3
  6  | 2011-02-25 00:00:00 |     4   | 2
  </code></pre>
  
  <p>I already have a solution for a specific user_id:</p>
  
  <pre><code>SELECT user_id, sessionDate, 
  abs(DATEDIFF((SELECT MAX(sessionDate) FROM session WHERE sessionDate &lt;  t.sessionDate and user_id = 1), sessionDate)) as Delta_in_days  
  FROM session AS t
  WHERE t.user_id = 1 order by sessionDate asc
  </code></pre>
  
  <p>But for more user_ids i didn´t find any solution</p>
  
  <p>Hope somebody can help me.</p>