碰到这种题,就想到子查询。害。。。。。。

select g.id, g.name, g.weight, temp.total from 
goods g join

(select goods_id, sum(t.count) as total FROM trans t
GROUP BY goods_id HAVING total > 20) temp

ON g.id = temp.goods_id  where g.weight < 50 ORDER BY g.id;