select g.id, g.name, g.description, g.bar_code, s.count as total_sales, r.count as total_receipts, r.count-s.count as total from good g join (select good_id, count(*) from receipt group by good_id) r on g.id = r.good_id
join (select good_id, count(*) from sale group by good_id) s on g.id = s.good_id