我有以下简单的表格:
CustomerID CustomerName NumOfOrders
1 Joe 15
2 Jane 20
7 Clara 1
我想找到订单数量最多的客户。看起来很琐碎,但我似乎无法找到解决方案。
答案 0 :(得分:4)
试试这个:
SELECT
*
FROM
my_table
ORDER BY
NumOfOrders DESC
LIMIT 1
答案 1 :(得分:2)
答案 2 :(得分: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
答案 3 :(得分:1)
SELECT CustomerID, NumOfOrders FROM myTable
where NumOfOrders =(select MAX(NumOfOrders) FROM myTable)
答案 4 :(得分:0)
试试这个......
select top 1 customerName from customer_Order order by numOfOrders desc
答案 5 :(得分:0)
您可以使用ORDER BY NumOfOrders DESC LIMIT 1