title: Subtract previous row value to current row
body: <p>I have the following table:</p>
  
  <pre><code>id  value  acc_no 
  -----------------
  1     12     1 
  2     14     1 
  3     15     1 
  4     10     2 
  5     16     2 
  6     19     1 
  7      7     3 
  8     24     2 
  </code></pre>
  
  <p>Expected output </p>
  
  <pre><code>id  value  acc_no   result 
  ------------------------------
  1     12     1          12(current row values of acc_no=1) 
  2     14     1          2(14 (current row values)-12(previous row value of acc_no=1))  
  3     15     1          1(15-14) 
  4     10     2          10(current row values of acc_no=2) 
  5     16     2          6(16 (current row values)-12(previous row value of acc_no=2)) 
  6     19     1          4(19(current row values)-15(previous row value of acc_no=1)) 
  7     7      3           7(current row values of acc_no=3) 
  8     24     2          8(24(current row values)-16(previous row value of acc_no=2)) 
  </code></pre>
  
  <p>I tried this query:</p>
  
  <pre><code>select 
      id, value,
      acc_no,
      (value - (select value from tb_acc t1 where t1.id = t.id - 1)) as result 
  from 
      tb_acc t
  </code></pre>
  
  <p>But I didn't get the proper output as expected</p>