题解 | 返回每个顾客不同订单的总金额
select cust_id, sum(item_price * quantity) total_ordered from Orders t1 left join OrderItems t2 on t1.order_num = t2.order_num group by cust_id order by total_ordered desc;
左联表,过滤掉没有cust_id的订单
select cust_id, sum(item_price * quantity) total_ordered from Orders t1 left join OrderItems t2 on t1.order_num = t2.order_num group by cust_id order by total_ordered desc;
左联表,过滤掉没有cust_id的订单
相关推荐