select
g.id,
g.name,
g.weight,
sum(t.count) as total
from
goods g
join trans t on g.id=t.goods_id
where
g.weight<50
group by
g.id,g.name,g.weight
having
sum(t.count)>20
order by
g.id asc
注意看两个表格的id含义不同

select
g.id,
g.name,
g.weight,
sum(t.count) as total
from
goods g
join trans t on g.id=t.goods_id
where
g.weight<50
group by
g.id,g.name,g.weight
having
sum(t.count)>20
order by
g.id asc
注意看两个表格的id含义不同