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