Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL: Customers With Multiple Orders

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL: Customers With Multiple Orders. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

The Cimpress Technology ordering platform needs to identify VistaPrint customers who placed multiple orders during the same calendar month. Write a PostgreSQL query that returns each qualifying customer, the month, and the number of orders placed during that month.

Requirements

  1. Join customers to orders using customer_id.
  2. Group orders by customer and calendar month, ignoring orders with a NULL order date.
  3. Return only customer-month groups with more than one order.
  4. Sort the output by customer_id and month ascending.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(120)Customer display name
orders
ColumnTypeDescription
order_idPKINTUnique order identifier
customer_idINTCustomer who placed the order
order_dateDATEDate the order was placed
Tablescustomersorders
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results