Skip to content
PMInterviewKit
← All questions
Technicalstandard

Write a SQL query to find the top 10 customers by number of orders last month, and explain how you would check the result.

How to approach it

Say the query in words first: filter orders to last month, group by customer, count, sort, take ten. Then name the traps.

How a strong answer opens

“In words: filter orders to last month, group by customer, count the orders, sort highest first and take the top ten. Then I'd check for canceled orders, test accounts and time zones.”

Outline of a strong answer

Try answering out loud for a few minutes before you open this.

  1. Filter the orders table to last month's date range
  2. Group by customer ID and count orders
  3. Sort by the count, highest first, and limit to 10
  4. Join to the customers table if names are needed
  5. Check: canceled orders, test accounts, time zones
  6. Sanity-check the totals against a known dashboard

Where this question usually goes wrong

Writing the query without defining last month, or skipping checks for canceled orders, test accounts and ties at tenth place.

Learn the method

Data and databases in Module 6, Technical for PMs.

The full kit has worked answers in full, start to finish, for every round type. $129 once.

Get one email when the full kit opens

No spam: just one launch email. See our privacy policy.