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