select g.id, g.name,g.weight,sum(t.count) as total from goods g join trans t on g.id = t.goods_id group by g.id having sum(t.count)>20 and weight<50 order by g.id selectt.goods_id as id,g.name,g.weight,sum(count) as totalfromgoods gjointrans t on g.id = t.goods_idgroup byt.goods_id, g.name, g....