Mysql打印前N行结果

时间:2013-11-26 00:58:19

标签: mysql

我有这张桌子:

Orders(Orderid,CustomerID,Amount)

我询问前10名客户(订单总额)的ID

我写了打印所有客户的查询(最高金额为最小金额)

select CustomerID, sum(Amount) as Total from orders group by CustomerID order by Total desc;

如何获得此结果的前10行?或者是我获得前十名错误的方式?

1 个答案:

答案 0 :(得分:1)

这是你想要的:

select CustomerID, sum(Amount) as Total
from orders 
group by CustomerID
order by Total desc
LIMIT 10;