title: Working with several line of Detail in SQL
body: <p>I got this problem
  I have this Table</p>
  
  <pre><code>Case     Order          Amount
  1         1               50
  1         2               20
  1         3               25 
  2         1               35
  2         2               40
  2         3               38
  3         1               45
  3         2               50
  3         3               25
  </code></pre>
  
  <p>So what I want is Case 1 Order 1 will subtract  the amount from Case 2 order 1, and then will subtract Case 3  Order 1  from Case 2 Order 1, then Case 1 order  2  subtract Case 2 Order 2 , then subtract Case 3 order 2  and so on 
  is like a chain reaction  </p>
  
  <p>Formula(Case 1 Order 1-Case 2 Order 1)-Case 3 order 1</p>
  
  <p>And the result have to be like this</p>
  
  <pre><code>Case     Order          Amount
  1         1               50
  1         2               20
  1         3               25 
  2         1               Result (35-50)=-15
  .         .
  3         1               Result (-15-45)
  </code></pre>