我有这张桌子:
Orders(Orderid,CustomerID,Amount)
我询问前10名客户(订单总额)的ID
我写了打印所有客户的查询(最高金额为最小金额)
select CustomerID, sum(Amount) as Total from orders group by CustomerID order by Total desc;
如何获得此结果的前10行?或者是我获得前十名错误的方式?
答案 0 :(得分:1)
这是你想要的:
select CustomerID, sum(Amount) as Total
from orders
group by CustomerID
order by Total desc
LIMIT 10;