title: expected that this query will not output 0 values, but it does
body: <p>I expected that this query will not output 0 values, but it does. I thought that <code>and (...) &gt; 0</code> will not output 0 values. So how I can prevent the output of 0 values?</p>
  <pre><code>select lot.*, sum(movement.quantity) as value 
  from lot
  left join lot_movement as movement on lot.id = movement.lot_id
  where lot.item_id = 8 and movement.storage_id = 3
  and (select sum(lot_movement.quantity) 
      from lot_movement 
      where lot_movement.lot_id = lot.id
      ) &gt; 0
  group by lot.id;
  </code></pre>
  <p>I tried to add <code>and sum(lot_movement.quantity) \&gt; 0</code>, but this gives error <code>invalid use of group function</code>.</p>
  <p><a href="https://i.stack.imgur.com/tpnM2.png" rel="nofollow noreferrer">lots in database</a></p>
  <p><a href="https://i.stack.imgur.com/8I9Nw.png" rel="nofollow noreferrer">lot_movements in database</a></p>
  <p><a href="https://i.stack.imgur.com/jUSfD.png" rel="nofollow noreferrer">output with 0 values</a></p>
  <p>I see that</p>
  <pre><code>and (select sum(lot_movement.quantity)
      from lot_movement
      where lot_movement.lot_id = lot.id
      group by lot_movement.lot_id) &gt; 0
  </code></pre>
  <p>is redundant. It doesn't affect the result.</p>