题解 | #返回顾客名称和相关订单号以及每个订单的总价#
返回顾客名称和相关订单号以及每个订单的总价
https://www.nowcoder.com/practice/4dda66e385c443d8a11570a70807d250
/*多表联结,分别通过相同的列将表关联起来,当中的select子句 相当于另外创建了一张表oo。 在不影响速度情况下,join可以多次使用 */ select c.cust_name, oo.order_num, oo.OrderTotal from Orders o join (select order_num, sum(quantity * item_price) OrderTotal from OrderItems group by order_num) oo on oo.order_num = o.order_num join Customers c on c.cust_id = o.cust_id order by c.cust_name, oo.order_num;