Rishabh Agarwal
Rishabh Agarwal

Reputation: 2644

Return Customer Number with highest number of order

Question,

You are given the table "ORDERS"

Return the customerNumber to the customer that has placed the highest number of order(it is guaranteed that there is only one customer with the most orders).

enter image description here

My guess was to return highest repeated customer number but couldn't get the exact syntax.

My Answer (Doesn't Work)

SELECT 'customerNumber' 

FROM 'ORDERS' 

GROUP BY 'customerNumber' 

ORDER BY COUNT(*) 

DESC LIMIT 1;

Upvotes: 1

Views: 2938

Answers (2)

Namya Aankur Gupta
Namya Aankur Gupta

Reputation: 9

Write your MySQL query statement below

SELECT customer_number FROM orders GROUP BY customer_number ORDER BY count(order_number) DESC LIMIT 1;

Upvotes: 0

Rishabh Agarwal
Rishabh Agarwal

Reputation: 2644

SELECT customerNumber 

FROM ORDERS 

GROUP BY customerNumber 

ORDER BY COUNT(*) 

DESC LIMIT 1;

Upvotes: 4

Related Questions