Click here to Skip to main content
15,881,616 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
write a sql query for that.

find the customer who placed maximum numbers of orders

example :

there is table called orders and in which there are two columns.

orderid|customerid
1 --------- 1
2 --------- 2
3 --------- 3
4 --------- 3


so the answer here is customerid=3.
Posted
Updated 28-Jun-22 22:26pm
v2

Try this:
SQL
SELECT customerid, COUNT(customerid) AS CountOfCust
FROM TableName
GROUP BY customerid


Now, you need to find maximum value ;)
 
Share this answer
 
Comments
Garth J Lancaster 19-Oct-14 6:40am    
bvgger - got there before me :-) - I was going to suggest top/limit
Maciej Los 19-Oct-14 6:42am    
;)
Member 10689154 19-Oct-14 7:07am    
thanks i have done it
Maciej Los 19-Oct-14 7:14am    
Please, accept my answer as a solution (green button) - formally, to remove question from unanswered list.
Member 10689154 19-Oct-14 6:46am    
how i find the maximum value
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!
 
Share this answer
 
Comments
Member 10689154 19-Oct-14 6:51am    
i think you don't know the answer.
OriginalGriff 19-Oct-14 7:02am    
Nice try.
I do - but so should you...
Try
Tble..Order
OrderId|CustomerId


SQL
select top 1 [CustomerId],count([OrderId]) as NoOfOrders from [dbo].[tbl_Order] group by [CustomerId] order by NoOfOrders desc
 
Share this answer
 
select * from(SELECT customerid,COUNT(orderid)
FROM table name
GROUP BY customerid
ORDER BY COUNT(orderid) DESC ) a
WHERE rownum = 1
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900