题解 | #计算总和#

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

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

因为表中没有total_ordered,我们先使用sum构造出来,然后两个表做内连接Join..on条件,连接条件是order_num.desc表示降序排列。 以下是代码:

select cust_id,total_ordered
from Orders o
join
(select 
 cust_num,sum(order_item *quantity) total_ordered
from OrderItms
group by order_num
)t
on o.order_num = t.order_num
order by total_ordered desc;



全部评论

相关推荐

点赞 评论 收藏
分享
我的代码出BUG了:@美团@腾讯@字节跳动@阿里巴巴。你们好好看看吧,你们就挂我吧,到时候被人家鸽穿还得录取我
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务