Query the customer_number from the orders table for the customer who has placed the largest number of orders. It is guaranteed that exactly one customer will have placed more orders than any other customer. The orders table is defined as follows:
| Column | Type |
|-------------------|-----------|
| order_number (PK) | int |
| customer_number | int |
| order_date | date |
| required_date | date |
| shipped_date | date |
| status | char(15) |
| comment | char(200) |
SELECT customer_numberFROM ordersGROUP BY customer_numberORDER BY COUNT(*) DESCLIMIT 1;
Follow up:
What if more than one customer have the largest number of orders, can you find all the customer_number in this case?
SELECT customer_numberFROM ordersGROUP BY customer_numberHAVING COUNT(order_number)= ( SELECT COUNT(order_number) FROM orders GROUP BY customer_number ORDER BY COUNT(order_number) DESC LIMIT 1 );