题解 | #返回每个顾客不同订单的总金额#
返回每个顾客不同订单的总金额
https://www.nowcoder.com/practice/ce313253a81c4947b20e801cd4da7894
-- 思路:先根据OrderItems查出每个order_num的总金额,将查出的表和Orders表内连接,连接后查每个cust_id的总金额 select cust_id, sum(o_total) as total_ordered from ( select order_num, sum(item_price * quantity) as o_total from OrderItems group by order_num ) as temp inner join Orders on temp.order_num = Orders.order_num group by cust_id order by total_ordered desc;