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

WITH t1 AS (
    SELECT a.goods_id,
           b.name,
           SUM(a.count) AS total,
           MAX(b.weight) AS weight_
    FROM trans a
    LEFT JOIN goods b
    ON a.goods_id = b.id
    GROUP BY a.goods_id, b.name
    HAVING total > 20 AND weight_ <50
)
SELECT goods_id AS id,
       name,
       weight_ AS weight,
       total
FROM t1
ORDER BY id ASC;

# 这道题关键在于重量是不可以叠加的,但数量可以!

全部评论

相关推荐

2024-12-12 20:49
深圳大学 算法工程师
华为 大模型算法 n*16
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务