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