Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Add-to-Cart to Checkout Conversion

HardSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Add-to-Cart to Checkout Conversion. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Amazon.com wants to compare shopping-funnel performance across marketplaces. Write a PostgreSQL query that calculates the conversion rate from add-to-cart to checkout for sessions recorded during January 1 through January 2, 2025.

A session counts in the denominator when it contains an add_to_cart event. It counts as converted only when the same session contains a checkout event after the add-to-cart event and within 24 hours.

Requirements

  1. Aggregate events at the user and session level before calculating conversion.
  2. Report add-to-cart sessions, converted sessions, and conversion rate percentage by marketplace.
  3. Include marketplaces with customers but no qualifying add-to-cart sessions, returning a NULL rate when the denominator is zero.
  4. Exclude events for customer IDs that are not present in customers and avoid division by zero.

Schema

customers
ColumnTypeDescription
customer_idPKINTAmazon customer identifier
marketplaceVARCHAR(20)Amazon marketplace code
funnel_events
ColumnTypeDescription
event_idPKINTUnique funnel event identifier
customer_idINTCustomer associated with the event
session_idVARCHAR(20)Shopping session identifier
event_typeVARCHAR(20)Funnel event name
event_tsTIMESTAMPTimestamp when the event occurred
Tablescustomersfunnel_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results