Find Customers Whose Quarterly Spend Fell by Half or More

Last updated: November 29, 2026

Quick Overview

Identify customers whose spend in the last complete quarter was at most half of their spend in the prior quarter, among customers who spent at least $100 in that prior quarter, including those who spent nothing.

Amazon
Data Manipulation (SQL/Python)
Data Scientist
Amazon
November 29, 2026
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Identify customers whose spend in the last complete quarter was at most half of their spend in the prior quarter, among customers who spent at least $100 in that prior quarter, including those who spent nothing.

A retention-risk query in the style of Amazon retail customer analytics, where a sharp drop in spend often precedes churn and triggers win-back campaigns. The interviewer checks that zero-spend quarters are not silently dropped before applying LAG.

What the Interviewer Expects
  • Aggregate spend per customer per quarter
  • Densify the customer by quarter grid so a zero-spend quarter is a row
  • Use LAG partitioned by customer to compare consecutive quarters
  • Apply a minimum prior-spend threshold to avoid noise
  • Restrict to the last complete quarter
Key Topics to Cover
LAG
densification
CROSS JOIN
churn risk
quarterly aggregation
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you exclude customers whose drop is explained by a one-off large purchase?
  • How would you look at the change relative to the same quarter last year to handle seasonality?
  • How would you rank the at-risk customers for a campaign with a limited budget?
  • How would you change this to measure order frequency instead of spend?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

Table orders(order_id, customer_id, order_ts, order_total, status). Use SHIPPED orders. "Prior quarter at least $100" keeps out customers whose spend is too small for a percentage to mean anything...

Approach

If I aggregate and then apply LAG, a customer with no orders this quarter has no row, so LAG never compares their quarters and the biggest drops disappear. The fix is to build a grid of every customer...


Submit Your Answer
Markdown supported