I expected that this query will not output 0 values, but it does. I thought that and (...) > 0 will not output 0 values. So how I can prevent the output of 0 values?
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
    ) > 0
group by lot.id;
I tried to add and sum(lot_movement.quantity) \> 0, but this gives error invalid use of group function.
I see that
and (select sum(lot_movement.quantity)
    from lot_movement
    where lot_movement.lot_id = lot.id
    group by lot_movement.lot_id) > 0
is redundant. It doesn't affect the result.
 
     
    