题解 | #返回每个顾客不同订单的总金额#
返回每个顾客不同订单的总金额
https://www.nowcoder.com/practice/ce313253a81c4947b20e801cd4da7894
SELECT cust_id,
(SELECT SUM(item_price*quantity)
FROM OrderItems #子查询对每个订单计算一次SUM()
WHERE OrderItems.order_num=Orders.order_num) as total_order # 子查询创建计算列
FROM Orders
ORDER BY total_order desc # order by 执行次序在 聚合函数、select 之后