Reputation: 1525
I have the following simple table:
CustomerID CustomerName NumOfOrders
1 Joe 15
2 Jane 20
7 Clara 1
I want to find the customer with maximum number of orders. Seems trivial enough but I can,t seem to find a solution.
Upvotes: 1
Views: 119
Reputation: 22915
select customername, sum(numOfOrders) as cnoo
from myTable
group by customername
order by cnoo
limit 1
and if customerName is unique (i.e. only one row per customer):
select customername
from myTable
order by numOfOrders desc
limit 1
Upvotes: 1
Reputation: 206
Try this....
select top 1 customerName from customer_Order order by numOfOrders desc
Upvotes: 0
Reputation: 8090
Try this:
SELECT
*
FROM
my_table
ORDER BY
NumOfOrders DESC
LIMIT 1
Upvotes: 4
Reputation: 40328
SELECT CustomerID, NumOfOrders FROM myTable
where NumOfOrders =(select MAX(NumOfOrders) FROM myTable)
Upvotes: 1
Reputation: 31647
How about this?
SELECT CustomerID, CustomerName, MAX(NumOfOrders) FROM myTable
Upvotes: 2