1

我有以下简单的表格:

CustomerID  CustomerName   NumOfOrders
1           Joe            15
2           Jane           20
7           Clara          1

我想找到订单数量最多的客户。似乎微不足道,但我似乎找不到解决方案。

4

6 回答 6

4

尝试这个:

SELECT
    *
FROM
    my_table
ORDER BY
    NumOfOrders DESC
LIMIT 1
于 2013-06-05T07:56:53.470 回答
2

这个怎么样?

SELECT CustomerID, CustomerName, MAX(NumOfOrders) FROM myTable

演示

于 2013-06-05T07:55:52.180 回答
1
select customername, sum(numOfOrders) as cnoo
from myTable
group by customername 
order by cnoo 
limit 1

如果 customerName 是唯一的(即每个客户只有一行):

select customername
from myTable
order by numOfOrders desc
limit 1
于 2013-06-05T07:55:22.447 回答
1
SELECT CustomerID, NumOfOrders FROM myTable
where  NumOfOrders  =(select MAX(NumOfOrders) FROM myTable)
于 2013-06-05T07:56:46.157 回答
0

您可以使用ORDER BY NumOfOrders DESC LIMIT 1

于 2013-06-05T09:11:25.563 回答
0

尝试这个....

select top 1 customerName from customer_Order order by numOfOrders desc
于 2013-06-05T08:06:34.607 回答