SELECT
    goods_id AS id,
    name,
    weight,
    SUM(count) AS total
FROM
    trans AS T
    LEFT JOIN goods AS G ON G.id = T.goods_id
GROUP BY
    goods_id
HAVING
    total > 20
    AND weight < 50
ORDER BY
    id ASC;