SELECT t1.customer_id FROM ( SELECT customer_id, SUM(amount) AS total_purchase FROM orders GROUP BY customer_id ) t1 JOIN ( SELECT customer_id, SUM(amount) AS total_purchase FROM orders GROUP BY customer_id ) t2 ON t1.customer_id = t2.customer_id AND t1.total_purchase > t2.total_purchase GROUP BY t1.customer_id HAVING COUNT(*) = COUNT(t1.total_purchase - t2.total_purchase) ORDER BY t1.customer_id;
该查询语句首先对顾客的总购买金额进行求和,然后通过自连接将每个顾客的当前总购买金额与其之前的总购买金额进行比较,只保留严格递增的顾客。最后根据顾客ID对结果进行排序返回。