Assign Marketplace Purchases to Promotion Windows with a Range Join

Last updated: November 29, 2026

Quick Overview

Given a promotions table (promo_id, category, start_date, end_date) whose windows can overlap and a purchases table (purchase_id, category, purchase_date, amount), attach to each purchase the active promotion for its category with the latest start date, or none, and total revenue per promotion.

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

0

0

0 solved


Given a promotions table (promo_id, category, start_date, end_date) whose windows can overlap and a purchases table (purchase_id, category, purchase_date, amount), attach to each purchase the active promotion for its category with the latest start date, or none, and total revenue per promotion.

Promotions analysis for Facebook Marketplace or Shops needs a non-equi join on date ranges, which pandas does not provide directly. The interviewer checks whether you merge on the equality key then filter on the range, control the blowup, and resolve overlapping windows deterministically.

What the Interviewer Expects
  • Merge on category then filter start <= date <= end
  • Resolve multiple matching promos with a clear rule
  • Left-join back so purchases with no promotion are kept
  • Aggregate revenue per promo including a 'none' bucket
  • Discuss memory blowup and alternatives (merge_asof, IntervalIndex)
Key Topics to Cover
range join
non-equi join
merge
deduplication
promotions
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 do this efficiently if each category had thousands of promotions?
  • How would you estimate incremental revenue from a promotion rather than attributed revenue?
  • What if end_date is exclusive in the source system?
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

Dates are inclusive on both ends. If two promotions are active for the same category on a purchase date, the one with the later start wins (it is the most recently launched), with promo_id as the fina...

Approach

Merge purchases with promotions on category, which yields every candidate promo per purchase. Filter to rows where the purchase date is within the window. Sort by purchase and start date descending an...


Submit Your Answer
Markdown supported