select
box_id, max(name), max(another_name), "product",
sum(coalesce(incoming::numeric, 0)) "incoming",
sum(coalesce(output::numeric, 0)) "output",
sum(coalesce(incoming::numeric, 0)) - sum(coalesce(output::numeric, 0)) "balance"
from table1
group by product, box_id
order by box_id;