title: difference query between two tables in Postgresql?
body: <p>In Postgresql I have table of <code>items</code> as follow:</p>
  
  <pre><code>id  qty 
  1    20
  2    45
  3    10
  </code></pre>
  
  <p>it contains the quantity of each product.
  I'm doing a counting operation. For every item I count I copy the data to a a <code>log_count</code> table.  Items table NEVER CHANGED.</p>
  
  <p>I want to write a query which will show me the difference between the tables. Basically how much left to pass over. When the quantity is 0 the row disappears.</p>
  
  <p>This is how it should be:</p>
  
  <p><strong>Start</strong>:</p>
  
  <pre><code>items:             log_count:              QUERY SHOW:
      1    20                                1        20
      2    45                                2        45
      3    10                                3        10
  </code></pre>
  
  <p>after doing count of: <code>id=1 qty=3</code></p>
  
  <pre><code>items:             log_count:              QUERY SHOW:
      1    20         1      3               1        17
      2    45                                2        45
      3    10                                3        10
  </code></pre>
  
  <p>later, after doing count of: <code>id=2 qty=45</code></p>
  
  <pre><code>items:             log_count:              QUERY SHOW:
      1    20         1      3               1        17
      2    45         2      45              3        10
      3    10                                * row of id 2 is gone as its qty=0
  </code></pre>
  
  <p>later, after doing count of: <code>id=1 qty=2</code></p>
  
  <pre><code>items:             log_count:              QUERY SHOW:
      1    20         1      5               1        15
      2    45         2      45              3        10
      3    10                               
  </code></pre>
  
  <p><strong>Final stage...</strong></p>
  
  <pre><code>items:             log_count:              QUERY SHOW:
      1    20         1      20             
      2    45         2      45             
      3    10         3      10                      
  </code></pre>
  
  <p>How do I write this query?</p>