select id,name,weight,total from goods , (select t.goods_id , sum(t.count) as total from trans t group by t.goods_id) ts where goods.id = ts.goods_id and (goods.weight<50 and ts.total > 20) 简简单单,照着条件写就行