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