SELECT
g.id as id,
name,
weight,
sum(count) as total

FROM goods g JOIN trans t ON g.id = t.goods_id
WHERE weight < 50
GROUP BY g.id, name, weight
HAVING sum(count) > 20 
ORDER BY g.id