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

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

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

全部评论

相关推荐

不愿透露姓名的神秘牛友
10-12 10:48
已编辑
秋招之苟:邻居家老哥19届双2硕大厂开发offer拿遍了,前几天向他请教秋招,他给我看他当年的简历,0实习实验室项目技术栈跟开发基本不沾边😂,我跟他说这个放在现在中厂简历都过不了
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务