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

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

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

-- 思路:先根据OrderItems查出每个order_num的总金额,将查出的表和Orders表内连接,连接后查每个cust_id的总金额
select
    cust_id,
    sum(o_total) as total_ordered
from
    (
        select
            order_num,
            sum(item_price * quantity) as o_total
        from
            OrderItems
        group by
            order_num
    ) as temp
    inner join Orders on temp.order_num = Orders.order_num
group by
    cust_id
order by
    total_ordered desc;

全部评论

相关推荐

冷艳的小师弟在看机会:jd测评乱点直接被挂了,哭死~
点赞 评论 收藏
分享
10-25 12:05
已编辑
湖南科技大学 Java
若梦难了:我有你这简历,已经大厂乱杀了
点赞 评论 收藏
分享
预计下个星期就能开奖吧,哪位老哥来给个准信
华孝子爱信等:对接人上周说的是这周
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务