select a.id, name, weight, sum(count) as total from goods a join trans b on a.id=b.goods_id where weight<50 group by a.id, name, weight having sum(count)>20 order by a.id