Find the customer who placed the most orders

Quick Overview

Write a SQL query over an Orders table that returns the customer number of the customer who placed the most orders. It tests counting rows per customer, picking the top group, and how a guarantee of a unique winner affects the query you write.

Find the customer who placed the most orders

Company: Databricks

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

The `Orders` table has one row per order. Write a query that returns the `customer_number` of the customer who placed the largest number of orders. ```hint Start with the counts Work out how many orders each customer has before deciding how to keep only the largest. ``` ### Input Table(s) `Orders` | Column | Type | Meaning | |---|---|---| | order_number | INT | Identifier of the order | | customer_number | INT | Customer who placed the order (NOT NULL) | Primary key: `order_number`. A customer can appear in many rows. ### Output Contract - One column: `customer_number` (INT). - Exactly one row, holding the customer with the most orders. - The result has a single row, so no ordering is required. No rounding applies. ### Example `Orders` | order_number | customer_number | |---|---| | 1 | 1 | | 2 | 2 | | 3 | 3 | | 4 | 3 | Expected result: | customer_number | |---| | 3 | Customer 3 has two orders, while customers 1 and 2 have one each, so customer 3 is returned. ### Constraints and Clarifications - `Orders` contains at least one row. - Exactly one customer has placed more orders than every other customer, so the answer is unique and there is no tie to break. - `customer_number` is never NULL. - `order_number` is unique, so each row counts as one order.

Overview: Write a SQL query over an Orders table that returns the customer number of the customer who placed the most orders. It tests counting rows per customer, picking the top group, and how a guarantee of a unique winner affects the query you write.

Databricks logo
Databricks
Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

The Orders table has one row per order. Write a query that returns the customer_number of the customer who placed the largest number of orders.

Input Table(s)

Orders

ColumnTypeMeaning
order_numberINTIdentifier of the order
customer_numberINTCustomer who placed the order (NOT NULL)

Primary key: order_number. A customer can appear in many rows.

Output Contract

  • One column: customer_number (INT).
  • Exactly one row, holding the customer with the most orders.
  • The result has a single row, so no ordering is required. No rounding applies.

Example

Orders

order_numbercustomer_number
11
22
33
43

Expected result:

customer_number
3

Customer 3 has two orders, while customers 1 and 2 have one each, so customer 3 is returned.

Constraints and Clarifications

  • Orders contains at least one row.
  • Exactly one customer has placed more orders than every other customer, so the answer is unique and there is no tie to break.
  • customer_number is never NULL.
  • order_number is unique, so each row counts as one order.