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

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