title: How to subtract second row from first row and generate a output column in mysql
body: <p>I have a situation, consider the following query :</p>
  
  <pre><code>select 
      A.cakename, A.status, B.ordertime
  from
      Cake as A
          inner join
      Orders as B on A.cakeid = B.cakeid
  </code></pre>
  
  <p>The output of this query </p>
  
  <pre><code>cakename,   status,      ordertime
  Apple Pie, available,    2014-03-20 22:34:46
  Apple Pie, available,    2014-10-10 04:00:00
  Apple Pie, available,    2015-03-20 22:34:46
  Brownie,   available,    2014-03-20 22:35:07
  Brownie,   available,    2015-05-20 22:35:07
  Brownie,   available,    2014-03-26 22:36:07
  Brownie,   available,    2015-05-20 14:35:48
  Brownie,   available,    2015-05-20 22:35:07
  Brownie,   available,    2015-05-10 22:35:07
  </code></pre>
  
  <p>Now I want to subtract the <code>ordertime row n+1 - ordertime row n</code> and create a separate column to store the result. For now you can ignore the last row since there will be no next row. </p>
  
  <p>For example: <code>2014-10-10 04:00:00</code> - <code>2014-03-20 22:34:46</code> this equation will be for first row, and its result will be stored in a new column lets take <code>difference of consecutive ordertime</code>. Could anyone give me some pointers to solve this situation ? </p>
  
  <p>If you could help to create a <code>auto increment column</code> that will be great because then I can self join and take the difference.</p>