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

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

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

总思路:
1、由OrderItems表查询得到每个订单总金额(total_order),将这个表命名为t
(但是没有顾客信息,因此需要与Order表相连接)
2、将包含每个订单总金额(total_order)的表t与包含顾客信息(cust_id)的表Orders相连接
3、筛选列cust_id, total_orderd
4、按total_orderd降序(desc)排列
#t表
select order_num,sum(item_price*quantity) as total_orderd
    from OrderItems
    group by order_num   
from Orders o
join 
	(select order_num,sum(item_price*quantity) as total_orderd
    from OrderItems
    group by order_num    
     ) t 
    using(order_num)
order by total_orderd desc
全部评论

相关推荐

1 收藏 评论
分享
牛客网
牛客企业服务