题解 | #商品交易(网易校招笔试真题)#

商品交易(网易校招笔试真题)

http://www.nowcoder.com/practice/f257dfc1b55e42e19eec004aa3cb4174

  • 参考答案
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条件即可

全部评论

相关推荐

点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务