题解 | #确定最佳顾客的另一种方式(二)#
确定最佳顾客的另一种方式(二)
https://www.nowcoder.com/practice/b5766f970ae64ac7944f37f5b47107aa
本题考察的点包括分组聚合及多表连接
select cust_name,total_price from Orders t1 join Customers t2 on t1.cust_id = t2.cust_id // 使用cust_id 连接 Orders表 与 Customers表 join (select order_num,sum(item_price*quantity) total_price from OrderItems group by order_num) t3 // 使用分组聚合函数求得各订单的订单总额 on t1.order_num = t3.order_num // 使用 order_num 连接OrderItems 表与上述两表 where total_price >= 1000 order by total_price asc // 按总价升序排列