题解 | #确定最佳顾客的另一种方式(二)#
确定最佳顾客的另一种方式(二)
https://www.nowcoder.com/practice/b5766f970ae64ac7944f37f5b47107aa
-- 简单写下思路,先写一个子查询查询出分组后的订单和,然后再查询对结果进行排序
select
cust_name,
total_price
from
(
select
c.cust_name,
sum(round(o.item_price * o.quantity, 3)) as total_price
from
OrderItems as o
join Orders as r on o.order_num = r.order_num
join Customers as c on r.cust_id = c.cust_id
group by c.cust_name
) as t
where
total_price >= 1000
order by
total_price


查看3道真题和解析