select  id,name,weight,total
from  goods  left join (
   select goods_id , sum(count) as total 
   from trans 
   group by goods_id
   having total  >20

)t  on  goods.id  = t.goods_id
where weight <50 
order by id