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