题解 | #确定最佳顾客的另一种方式(二)#

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

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

# 方法1:内连接
select  c.cust_name,sum(oi.quantity*oi.item_price)total
from Customers c,Orders o,OrderItems oi
where c.cust_id=o.cust_id
and o.order_num=oi.order_num
group by  c.cust_name
having total>=1000;

# 方法2:先筛选后链接
select c.cust_name,cus_total.total
from orders o,
     customers c ,
     (select order_num,sum(item_price*OrderItems.quantity)total
        from orderitems
        group by order_num
      having sum(item_price*OrderItems.quantity)>=1000) as cus_total
where cus_total.order_num=o.order_num
and o.cust_id=c.cust_id;

全部评论

相关推荐

09-27 00:29
东北大学 Java
伟大的麻辣烫:查看图片
阿里巴巴稳定性 75人发布 投递阿里巴巴等公司10个岗位
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务