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