9. Highest Order Placing Customer
As a business, you want to identify which customer places the most orders. This is useful for targeting high-value customers with loyalty programs or marketing campaigns.
You are given a table named Orders that tracks customer orders.
āāāāāāāāāāāāāāāāāāā¦āāāāāāāāāāā ā Column Name ā Type ā ā āāāāāāāāāāāāāāāāāā¬āāāāāāāāāā⣠ā order_number ā int ā āāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāā ā customer_number ā int ā āāāāāāāāāāāāāāāāāāā©āāāāāāāāāāā
- order_number: Unique order ID (Primary Key) for each order placed.
- customer_number: ID of the customer who placed the order.
Write a query to find the customer_number of the customer who has placed the most orders. It is guaranteed that exactly one customer will have placed more orders than any other.
Example 1:
Example:
Input:
Orders Table
āāāāāāāāāāāāāāāā¦āāāāāāāāāāāāāāāāāā ā order_number ā customer_number ā ā āāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāā⣠ā 1 ā 1 ā āāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāā ā 2 ā 2 ā āāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāā ā 3 ā 3 ā āāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāā ā 4 ā 3 ā āāāāāāāāāāāāāāāā©āāāāāāāāāāāāāāāāāā
Expected Output:
āāāāāāāāāāāāāāāāāāā ā customer_number ā ā āāāāāāāāāāāāāāāāā⣠ā 3 ā āāāāāāāāāāāāāāāāāāā
Explanation:
- Customer 1 placed 1 order.
- Customer 2 placed 1 order.
- Customer 3 placed 2 orders (most orders).
Thus, the result is customer_number 3.
Still unsure what the problem is asking ?
Letās go through a few more examples, step by step, to make it clearer.