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

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

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;

全部评论

相关推荐

想申请延毕了,找工作找到崩溃,越找就越想摆烂,还有25届的和我一样感受吗?
码农索隆:没事哒,好兄弟,慢慢来,调整心态,车到山前必有路,感到迷茫的时候,多抬头看看
点赞 评论 收藏
分享
高斯林的信徒:武大简历挂?我勒个骚岗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务