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