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