Calculate Cart Abandonment Rate by Device Within Twenty-Four Hours
Last updated: November 29, 2026
Quick Overview
For each device type, compute the share of add-to-cart events that were not followed by a purchase of the same ASIN by the same customer within 24 hours.
Amazon
November 29, 20260
0
0 solved
For each device type, compute the share of add-to-cart events that were not followed by a purchase of the same ASIN by the same customer within 24 hours.
A funnel query in the style of Amazon checkout analytics, where abandonment by device (app, mobile web, desktop) guides where to invest in checkout fixes. The interviewer checks a correct anti-join with a time window, matching on ASIN, and exclusion of adds whose window has not finished.
What the Interviewer Expects
- Define abandonment at the add-to-cart event level, matched by customer and ASIN
- Use LEFT JOIN or NOT EXISTS with a 24 hour window
- Exclude adds within 24 hours of the data cutoff
- Count each add once even if several purchases match
- Attribute the add to the device where it happened, and state that purchases may happen on another device
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 results change if you matched on customer only, not ASIN?
- How would you treat Save for Later moves?
- How would you compute the median time from add to purchase for converted adds?
- How would you check whether the abandonment gap between devices is significant?
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
Table cart_events(customer_id, asin, event_ts, event_type, device_type) with event_type in add_to_cart or purchase. Cross-device purchases are common (add on the phone, buy on desktop), so mat...
Approach
- Take add-to-cart events whose 24 hour window ends before the last event in the data.
- Left join purchases by the same customer and ASIN with
purchase_tsin(add_ts, add_ts + 24 hours]. - An ...