题解 | #返回顾客名称和相关订单号以及每个订单的总价#

返回顾客名称和相关订单号以及每个订单的总价

http://www.nowcoder.com/practice/4dda66e385c443d8a11570a70807d250

  • 先两个表用cust_id连接一下,再与第三个表用order_num连接,然后按条件查询。
  • 由于计算的是每一个订单的总金额,所以不需要分组。
SELECT temp.cust_name, temp.order_num, (quantity* item_price) AS OrderTotal
FROM 
(SELECT cust_name, order_num
FROM Customers c
JOIN Orders o ON c.cust_id = o.cust_id) AS temp
JOIN OrderItems ot ON temp.order_num = ot.order_num
ORDER BY cust_name, order_num ASC;
全部评论

相关推荐

01-16 21:34
武汉大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务