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