/*使用相关子查询*/ # 查询某个顾客的所有订单的订单总金额 select sum(item_price*quantity) from OrderItems oi join Orders o on oi.order_num=o.order_num where cust_id=cust_id_num # 其中cust_id_num从主查询中获得 # 查询各顾客已订购的总金额 select cust_id, ( select sum(item_price*quantity) from OrderItems oi join Orders o on oi.order_num=o.order_num where cust_id=Orders.cust_id ) total_ordered from Orders order by total_ordered desc;