WITH goodstotal AS(
SELECT
    g.id,
    SUM(t.count) AS total
FROM
    goods AS g 
    INNER JOIN 
    trans AS t ON g.id=t.goods_id
GROUP BY
    g.id)
SELECT
    g.id,
    g.name,
    g.weight,
    gt.total
FROM
    goods AS g 
    INNER JOIN
    goodstotal AS gt ON g.id=gt.id
WHERE
    g.weight<50;