select gs.id,
       gs.name,
       gs.weight,
       a.total
from goods gs
         left join (select
         goods_id,sum(count) as  total
         from trans
         group by goods_id) as a
          on gs.id = a.goods_id
where a.total > 20
  and gs.weight < 50
order by gs.id