题解 | #返回顾客名称和相关订单号以及每个订单的总价#
返回顾客名称和相关订单号以及每个订单的总价
https://www.nowcoder.com/practice/4dda66e385c443d8a11570a70807d250
本文考察的要点应该是多表(三个及以上)连接,思路与两表连接一样,选择相应的连接关系(left join、right join、join)进行连接即可。
select cust_name,t2.order_num,OrderTotal from Customers t1 join Orders t2 on t1.cust_id = t2.cust_id // 连接Customers表 与 Orders表 join (select order_num,quantity*item_price OrderTotal from OrderItems) t3 // 将订单编号与订单总价查询后生成新表进行连接 on t2.order_num = t3.order_num order by cust_name asc,t2.order_num asc // 按顾客姓名、订单编号降序排列