Write SQL for Brand-Level 90 Day Reorder Rate From Retailer Order History

Last updated: November 29, 2026

Quick Overview

Given a wholesale orders table, compute for each brand the share of retailers whose first order with that brand was placed in a given quarter and who placed a second order with the same brand within 90 days of that first order. Exclude retailers whose 90 day window has not finished.

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

0

0

0 solved


Given a wholesale orders table, compute for each brand the share of retailers whose first order with that brand was placed in a given quarter and who placed a second order with the same brand within 90 days of that first order. Exclude retailers whose 90 day window has not finished.

Reorder rate is one of the clearest signals that a brand's products sell through in independent stores, and it feeds brand health dashboards and ranking features. The interviewer checks window functions, cohort definition per brand and retailer pair, and right censoring.

What the Interviewer Expects
  • Define the cohort per (brand, retailer) pair by first order date
  • Use ROW_NUMBER or MIN to find first and second orders
  • Measure the gap between first and second order in days
  • Exclude pairs whose observation window is incomplete
  • Report numerator, denominator and rate per brand
Key Topics to Cover
window functions
cohort analysis
right censoring
CTEs
reorder rate
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 add a minimum cohort size before showing the rate to a brand?
  • How would you compute this incrementally every day?
  • Should cancelled or fully returned orders count as orders here?
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

orders(order_id, brand_id, retailer_id, created_at TIMESTAMP, status). Count only orders not cancelled. Quarter is a parameter: :q_start inclusive and :q_end exclusive. Today is :as_of. A reor...

Approach

Rank each pair's orders by time. Keep rank 1 as the opening order and rank 2 as the candidate reorder. Filter openings to the quarter and to openings at least 90 days before :as_of, so every pair ha...


Submit Your Answer
Markdown supported

Related Questions