题解 | #返回每个顾客不同订单的总金额#

返回每个顾客不同订单的总金额

https://www.nowcoder.com/practice/ce313253a81c4947b20e801cd4da7894

# SELECT cust_id, 
#         (SELECT SUM(quantity*item_price)
#         FROM OrderItems
#         WHERE OrderItems.order_num = Orders.order_num) as total_ordered
# FROM Orders
# Order by total_ordered DESC       

SELECT 
    o.cust_id cust_id,
    tb.total_ordered total_ordered
FROM (
    SELECT
        order_num,
        SUM(item_price * quantity) total_ordered
    FROM
        OrderItems
    GROUP BY
        order_num
    ) tb inner join
    Orders o
on
    tb.order_num = o.order_num
ORDER BY
    total_ordered DESC;

全部评论

相关推荐

11-08 13:58
门头沟学院 Java
程序员小白条:竟然是蓝桥杯人才doge,还要花钱申领的offer,这么好的公司哪里去找
点赞 评论 收藏
分享
我已成为0offer的糕手:别惯着,胆子都是练出来的,这里认怂了,那以后被裁应届被拖工资还敢抗争?
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务