• 参考答案
select 
    g.id,
    g.name,
    g.weight,
    t2.total
from goods g , (
    select goods_id,
    sum(t.count) total
    from trans t
    group by goods_id) t2
where g.id = t2.goods_id
    and g.weight<50
    and t2.total>20
order by g.id

  • 本题解析
    g.id,
    g.name,
    g.weight,
    这三条数据可以直接从goods表中查询

每个分类的总重量可以按照goods_id分组求和
最后按照条件限制写出where条件即可