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