采用内连接

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