题解 | #返回每个顾客不同订单的总金额#
返回每个顾客不同订单的总金额
https://www.nowcoder.com/practice/ce313253a81c4947b20e801cd4da7894
#第一步对表OrderItems聚合
# SELECT
# order_num,
# SUM(item_price * quantity) total_ordered
# FROM
# OrderItems
# GROUP BY
# order_num
#第二步表连接
select
cust_id
,tb.total_ordered
from( SELECT
order_num,
SUM(item_price * quantity) total_ordered
FROM
OrderItems
GROUP BY
order_num) tb
inner join Orders o on tb.order_num=o.order_num
order by tb.total_ordered desc
小天才公司福利 1216人发布