title: sql query to divide a value over different records
body: <p>Consider the following recordset:</p>
  
  <pre><code>1 1000  -1
  2 500   2
  3 1000 -1
  4 500   3
  5 500   2
  6 1000 -1
  7 500   1
  </code></pre>
  
  <p>So 3x a number 1000 with -1, total -3.</p>
  
  <p>4x a number 500 with different values</p>
  
  <p>Now I'm in need of a query which divides the sum of code 1000 over the 4 number 500 and removes code 1000. 
  So the end result would look like:</p>
  
  <pre><code>1 500   1.25
  2 500   2.25
  3 500   1.25
  4 500   0.25
  </code></pre>
  
  <p>The sum of code 1000 = -3
  There's 4 times code 500 in the table over which -3 has to be divided.
  -3/4 = -0.75</p>
  
  <p>so the record "2 500 2" becomes "2 500 (2+ -0.75)" = 1.25</p>
  
  <p>etc</p>
  
  <p>As an SQL newbie I have no clue how to get this done, can anyone help?</p>