题解 | #返回顾客名称和相关订单号以及每个订单的总价#

返回顾客名称和相关订单号以及每个订单的总价

http://www.nowcoder.com/questionTerminal/4dda66e385c443d8a11570a70807d250

with tb as 
(
    select o.cust_id,sum(o1.quantity*o1.item_price) as a ,o1.order_num
    from Orders o inner join OrderItems o1 on o.order_num = o1.order_num
    group by o1.order_num,o.cust_id
)
select c.cust_name,t.order_num,t.a as OrderTotal from Customers c inner join tb t 
on c.cust_id = t.cust_id order by c.cust_name asc,t.order_num asc
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务