题解 | #确定最佳顾客的另一种方式(二)#
确定最佳顾客的另一种方式(二)
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;