SELECT goods.*,t.total
FROM goods,(SELECT trans.goods_id,sum(trans.count) total FROM trans GROUP BY trans.goods_id) t
where goods.id = t.goods_id and goods.weight < 50 and t.total > 20 ORDER BY goods.id