题解 | #返回顾客名称和相关订单号以及每个订单的总价#
返回顾客名称和相关订单号以及每个订单的总价
https://www.nowcoder.com/practice/4dda66e385c443d8a11570a70807d250
SELECT a.cust_name, b.order_num, c.quantity*c.item_price OrderTotal FROM Customers a LEFT JOIN Orders b ON a.cust_id = b.cust_id LEFT join OrderItems c ON b.order_num = c.order_num ORDER BY a.cust_name, b.order_num;
题解:
1.查询顾客名称、订单号和对应的总价,分别来源于三个不同的表
2.排序
思路:
1.先查询三个指定的字段,最后一个字段是计算字段
2.根据表间关系进行联结,这里使用左连接
3.排序