我有以下简单的表格:
CustomerID CustomerName NumOfOrders
1 Joe 15
2 Jane 20
7 Clara 1
我想找到订单数量最多的客户。似乎微不足道,但我似乎找不到解决方案。
我有以下简单的表格:
CustomerID CustomerName NumOfOrders
1 Joe 15
2 Jane 20
7 Clara 1
我想找到订单数量最多的客户。似乎微不足道,但我似乎找不到解决方案。
尝试这个:
SELECT
*
FROM
my_table
ORDER BY
NumOfOrders DESC
LIMIT 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
SELECT CustomerID, NumOfOrders FROM myTable
where NumOfOrders =(select MAX(NumOfOrders) FROM myTable)
您可以使用ORDER BY NumOfOrders DESC LIMIT 1
尝试这个....
select top 1 customerName from customer_Order order by numOfOrders desc