Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for Top LTV Holiday Customers

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

Your question is SQL for Top LTV Holiday Customers. 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

Shutterfly wants to target its highest-value customers who were active during the most recent holiday season. Write a PostgreSQL query using completed orders to find customers in the top 10% by lifetime value who made at least one completed purchase from November 1 through December 31, 2025.

Requirements

  1. Calculate lifetime value as the sum of completed order amounts across all available order history.
  2. Rank all customers into ten lifetime-value deciles, including customers with no completed orders.
  3. Keep only customers in the top decile who completed at least one purchase during the holiday period.
  4. Return the customer ID, name, lifetime value, and holiday order count, sorted by lifetime value descending.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer's name
orders
ColumnTypeDescription
order_idPKINTUnique order identifier
customer_idINTCustomer who placed the order
order_dateDATEDate the order was placed
order_amountDECIMAL(10,2)Revenue associated with the order
statusVARCHAR(20)Order processing status
Tablescustomersorders
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results