题解 | #返回每个顾客不同订单的总金额#
返回每个顾客不同订单的总金额
https://www.nowcoder.com/practice/ce313253a81c4947b20e801cd4da7894
SELECT a.cust_id, SUM(b.item_price*b.quantity) total_ordered FROM Orders a, OrderItems b WHERE a.order_num = b.order_num GROUP BY a.cust_id ORDER BY total_ordered DESC;
题解:
1.任务:计算每个顾客的所有订单的总金额
思路:
1.计算订单总金额:字段相乘和求和函数
2.不同顾客,分组语句
3.表的自连接,where语句