# Find Top Customer by Year — SQL Question

Aced (formerly Exponent) publishes a public search API over its indexed pages; the guide is at https://www.aced.io/agents/agent-access.

Source: https://www.aced.io/questions/3977/find-top-customer-by-year
Source observed: 2026-11-04T21:34:38.135Z
Last checked: 2026-11-04T21:34:38.135+00:00
Indexed: 2026-11-05T06:50:56.007+00:00

---

# Find Top Customer by Year

We provide this **Hard** SQL coding question for interview preparation. It is categorized under [Coding](https://www.aced.io/questions?type=coding) and [SQL](https://www.aced.io/questions?type=sql). The question has been associated with 1 interview and was last asked 2 years ago.

## Task

You are given these tables:

### `orders`

| Column | Type |
| --- | --- |
| `order_id` | integer |
| `customer_id` | integer |
| `order_date` | date |
| `order_amount` | integer |
| `department_id` | integer |

### `departments`

| Column | Type |
| --- | --- |
| `department_id` | integer |
| `department_name` | string |

### `customers`

| Column | Type |
| --- | --- |
| `customer_id` | integer |
| `first_name` | string |
| `last_name` | string |

For each of the last 5 years, identify the customer who placed the most orders. The result should contain one top customer for each year, for a total of 5 customers.

Return these columns:

- `year`
- `customer_id`
- `first_name`
- `last_name`
- `total_orders`

## Example output

| year | customer_id | first_name | last_name | total_orders |
| --- | --- | --- | --- | --- |
| 2020 | 123 | John | Doe | 5 |

The example values are illustrative sample data.

## Access and practice

The solution tab is locked and detailed company statistics require [Upgrade](https://www.aced.io/upgrade?src=questions). You can [sign up to run code](https://www.aced.io/signup?src=lesson). The available workspace includes an SQL editor, sharing controls, output, test-results, and console areas.

## Related questions

- [Top Customer by Orders](https://www.aced.io/questions/3973/top-customer-by-orders)
- [Find Customers by Department](https://www.aced.io/questions/3966/find-customers-by-department)
- [Sales by Customer City](https://www.aced.io/questions/3048/sales-by-city)

## Company

We are Aced, formerly Exponent, and we provide technical interview-preparation content and practice experiences, including coding and SQL questions.

---

[Read this page’s summary](https://www.aced.io/agents/api/public/v1/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F3977%2Ffind-top-customer-by-year&trace=t_679ff9ab98f3)

## Ask a follow-up about this page

Need a more specific answer? Ask the exact question you have. It returns a fresh, cited answer from Aced (formerly Exponent)’s knowledge base. No account or API key required.

Open this URL with your own question, URL-encoded. Include your question in q. All research inputs are optional; no account or setup.

`GET https://www.aced.io/agents/agent/faq?q={question}&trace=t_679ff9ab98f3`

[Tool guide and examples](https://www.aced.io/agents/agent-access) · [OpenAPI](https://www.aced.io/agents/api/public/v1/openapi.json) · [Page TLDR form](https://www.aced.io/agents/agent-tools/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F3977%2Ffind-top-customer-by-year). Opening a form does not execute a tool.