Flag Offers Priced Below Their Trailing Thirty Day Minimum
Last updated: November 29, 2026
Quick Overview
Given a daily_offer_price table with one row per ASIN per day (asin, price_date, price), return every ASIN-day where the price is strictly lower than the lowest price on any of the previous 30 days, only when a full 30 days of history exists.
Amazon
November 29, 20260
0
0 solved
Given a daily_offer_price table with one row per ASIN per day (asin, price_date, price), return every ASIN-day where the price is strictly lower than the lowest price on any of the previous 30 days, only when a full 30 days of history exists.
Amazon's pricing teams and deal programs care about 'lowest price in 30 days' because it defines whether a discount is genuine and feeds price-drop alerts. The interviewer is looking for a window frame that excludes the current row, and for honest handling of ASINs without enough history.
What the Interviewer Expects
- Use a frame of 30 PRECEDING to 1 PRECEDING so today's price is not compared with itself
- Require a full window of history using a COUNT over the same frame
- Filter in an outer query because window results cannot be used in WHERE directly
- State the dense one-row-per-day assumption and what breaks if it is false
- Use strict less-than and explain the choice
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
- What if some days are missing from the table, so 30 rows is more than 30 days?
- How would you also return the date the previous minimum was set?
- How would you suppress repeated flags when the price keeps dropping day after day?
- How would you run this daily for 500 million ASINs efficiently?
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
daily_offer_price(asin, price_date, price): one row per ASIN per calendar day, for example a nightly snapshot of the featured offer. I will confirm the table is dense; if it is not, a rows-based f...
Approach
Compute two window aggregates over the same frame ROWS BETWEEN 30 PRECEDING AND 1 PRECEDING: the minimum price and the count of rows. The count guards against a short history, where a 5-day minimum ...