我正在寻找解决方案:
客户可以在 y 的时间以 x 的价格下订单。客户可以拥有无限数量的订单。
我希望在一个时间范围内(例如一个月)让 z 顶级客户获得订购金额。
我坚持总结和排序/过滤到顶部 z 。
你能救我吗?谢谢!答案 0 :(得分:0)
给定一个包含customer_id,amount和time列的订单表,您应该可以执行以下操作:
SELECT customer_id, sum(amount) AS total
FROM orders
GROUP BY customer_id
WHERE time BETWEEN start AND end
ORDER BY total DESCENDING
LIMIT 3
答案 1 :(得分:0)
这是伪代码,但我会使用类似的东西:
select sum(order_total), client_id
from orders
where order_date between X and Y
group by client_id
order by sum(order_total)
limit 0, 10