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

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

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

select 
t2.cust_id,sum(t1.item_price*t1.quantity) as total_ordered
from OrderItems t1
left join Orders t2
on 
t1.order_num = t2.order_num
group by 
t2.cust_id
having  t2.cust_id is not NULL
order by 
total_ordered DESC

这里使用了Left join 的方式,来进行多表查询,选择OrderItems表作为驱动表,查询条件为 t1.order_num = t2.order_num

,找出符合条件的数据,但是还要保证右表的t2.cust_id不能为空。这是需要过滤的数据

全部评论

相关推荐

炫哥_:哥们项目描述里面vector和mysql之类的都要写吗,直接开头技术栈巴拉巴拉就行了,完全不是技术点啊
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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