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