找出每个客户金额最大的那一笔订单。
- 订单金额
amount= 该订单所有订单行的qty × unit_price之和(忽略折扣,不区分订单状态)。没有订单行的订单不参与比较。 - 对每个
customer_id,取amount最大的订单;金额并列时取order_id较小的那一笔,因此每个客户恰好输出一行。 customer_id为 null 的订单忽略。客户表不参与本题,customer_id在客户表里查不到的订单照常计算。
输入
orders(order_id, customer_id, order_ts, status, channel)order_items(order_id, product_id, qty, unit_price, discount)
输出
列为 customer_id, order_id, amount,行顺序不限。