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