*题解 | #确定最佳顾客的另一种方式(二)# 直接表联合

确定最佳顾客的另一种方式(二)

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


# 【问题】编写 SQL 语句,返回订单总价不小于1000 的客户名称和总额(OrderItems 表中的order_num)。
# 提示:需要计算总和(item_price 乘以 quantity)。按总额对结果进行排序,请使用INNER JOIN 语法。

# 使用innerjoin
select cust_name,
sum(item_price*quantity) as total_price

from  OrderItems a 
inner join Orders b on a.order_num=b.order_num 
inner join Customers c on b.cust_id =c.cust_id
group by cust_name #因为select中的非聚合函数要在groupby出现
having total_price>=1000
order by total_price;

# 使用where 
select cust_name,
sum(item_price*quantity) as total_price

from  OrderItems a ,Orders b ,Customers c
where a.order_num=b.order_num and  b.cust_id =c.cust_id
group by cust_name #因为select中的非聚合函数要在groupby出现
having total_price>=1000
order by total_price






SQL错题 文章被收录于专栏

每天学习一遍 刷题刷题 越刷越强!

全部评论

相关推荐

07-02 18:09
门头沟学院 Java
苍穹外卖和谷粒商城这俩是不是烂大街了,还能做吗?
想去重庆的鸽子在吐槽:你不如把这俩做完自己搞明白再优化点再来问 何必贩卖焦虑
点赞 评论 收藏
分享
05-30 12:03
山西大学 C++
offer来了我跪着...:不是骗子,等到测评那一步就知道为啥这么高工资了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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