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