题解 | #确定最佳顾客的另一种方式(二)#
确定最佳顾客的另一种方式(二)
https://www.nowcoder.com/practice/b5766f970ae64ac7944f37f5b47107aa
1 . 先使用3张表的内连接获得所有的顾客所对应的订单号所对应的订单金额,然后根据 cust_name,order_num 分组统计计算每个顾客对应的总金额并按照总金额升序排序。
select cust_name ,
       sum(OI.item_price*OI.quantity) total_price 
    from Customers C
   inner join Orders O on C.cust_id = O.cust_id 
   inner join OrderItems OI on O.order_num = OI.order_num 
   group by C.cust_name ,O.order_num 
   having total_price >= 1000 
   order by total_price ; 
