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