select g.id,name,weight,sum(count) sums from goods g join trans t on g.id = t.goods_id group by g.id having sums>20 and weight<50 order by g.id;