Customer Placing the Largest Number of Orders LeetCode Solution

Last updated on January 22nd, 2025 at 11:21 pm

Here, we see the Customer Placing the Largest Number of Orders LeetCode Solution. This Leetcode problem is solved using MySQL and Pandas.

List of all LeetCode Solution

Level of Question

Easy

Customer Placing the Largest Number of Orders LeetCode Solution

Customer Placing the Largest Number of Orders LeetCode Solution

1. Problem Statement

Column NameType
order_numberint
customer_numberint
Table: Orders

order_number is the primary key (column with unique values) for this table. This table contains information about the order ID and the customer ID.

Write a solution to find the customer_number for the customer who has placed the largest number of orders.

The test cases are generated so that exactly one customer will have placed more orders than any other customer.

The result format is in the following example.

Example 1:
Input:

order_numbercustomer_number
11
22
33
43
Orders table:

Output:

customer_number
3

Explanation: The customer with number 3 has two orders, which is greater than either customer 1 or 2 because each of them only has one order. So the result is customer_number 3.

2. Code Implementation in Different Languages

2.1 Customer Placing the Largest Number of Orders MySQL

select 
  customer_number 
from 
  (
    select 
      customer_number, 
      count(*) as cnt 
    from 
      orders 
    group by 
      customer_number
  ) as e 
order by 
  e.cnt desc 
limit 
  1;
Scroll to Top