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

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

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-01 11:47
点赞 评论 收藏
分享
但听说转正率很低,我现在有在实习了,好纠结要不要去
熬夜脱发码农:转正率低归低,但是实习的经历你可以拿着,又不是说秋招不准备了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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