Measure Unit Sales Seven Days Before and After Each Price Change
Last updated: November 29, 2026
Quick Overview
From daily price snapshots and daily unit sales per ASIN, detect every price change and compare average daily units in the seven days before the change to the seven days after.
Amazon
November 29, 20260
0
0 solved
From daily price snapshots and daily unit sales per ASIN, detect every price change and compare average daily units in the seven days before the change to the seven days after.
A pricing analytics question in the style of Amazon retail pricing teams, who study how demand responds to price moves. The interviewer checks LAG-based change detection, correctly bounded before and after windows, zero-sale days, and caution about reading the result as elasticity.
What the Interviewer Expects
- Detect price changes with LAG over daily snapshots
- Define before as days -7 to -1 and after as days 0 to 6 relative to the change
- Fill zero-sale days so averages are per calendar day
- Exclude changes without a full window on both sides
- Report percentage price change next to percentage unit change
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you handle a second price change inside the seven-day window?
- How would you estimate elasticity while controlling for seasonality?
- How would you compare against similar ASINs whose price did not change?
- How would you treat stockouts that suppress units after a change?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
Tables:
price_snapshots(asin, snapshot_date, price): one row per ASIN per day.daily_units(asin, sale_date, units): only days with sales have rows.dim_date(cal_date)calendar.
A change i...
Approach
LAG(price)per ASIN gives the previous price; keep rows where they differ.- Densify units: cross the ASIN's change windows with the calendar and left join sales so a day with no sales counts as...