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

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

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

#第一步对表OrderItems聚合
        # SELECT
        #     order_num,
        #     SUM(item_price * quantity) total_ordered
        # FROM
        #     OrderItems
        # GROUP BY
        #     order_num
#第二步表连接
select
cust_id
,tb.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 tb.total_ordered desc

全部评论

相关推荐

11-03 14:38
重庆大学 Java
AAA求offer教程:我手都抬起来了又揣裤兜了
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务