题解 | #返回每个顾客不同订单的总金额#

返回每个顾客不同订单的总金额

https://www.nowcoder.com/practice/ce313253a81c4947b20e801cd4da7894

SELECT
  cust_id,
  total_ordered
FROM
  Orders c
  INNER JOIN (
    SELECT
      order_num,
      SUM(item_price * quantity) total_ordered
    FROM
      OrderItems
    GROUP BY
      order_num
  ) o ON o.order_num = c.order_num
ORDER BY
  o.total_ordered DESC

#愚人节我想对你说#
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务