Back to questions

Same Week Purchases Etsy SQL Interview Question

Same Week Purchases

Etsy SQL Interview Question

This is the same question as problem #29 in the SQL Chapter of Ace the Data Science Interview!

You are given the two tables containing information on Etsy’s user signups and purchases. Write a query to obtain the percentage of users who signed up and made a purchase within 7 days of signing up. The result should be rounded to the nearest 2 decimal places.

Assumptions:

  • Signups who didn't buy any products yet should also count as part of the percentage of users who signed up and made a purchase within 7 days of signing up
  • If the signup date is on 06/21/2022 and the purchase date on 06/26/2022, then the user makes up part of the percentage of users who signed up and purchased within the 7 days of signing up.

Table:

Column NameType
user_idinteger
signup_datedatetime

Example Input:

user_idsignup_date
44506/21/2022 12:00:00
74206/19/2022 12:00:00
64806/24/2022 12:00:00
78906/27/2022 12:00:00
12306/27/2022 12:00:00

Table:

Column NameType
user_idinteger
product_idinteger
purchase_amountdecimal
purchase_datedatetime

Example Input:

user_idproduct_idpurchase_amountpurchase_date
244757545.0006/22/2022 12:00:00
742124150.0006/28/2022 12:00:00
648363255.5006/25/2022 12:00:00
123847567.3006/29/2022 12:00:00
244234174.1006/30/2022 12:00:00

Example Output:

single_purchase_pct
40.00

Explanation: The only users who purchased within 7 days of signing up are users 648 and 123. The total count of given signups is 5, resulting in a percentage of 2/5 = 40%.

The dataset you are querying against may have different input & output - this is just an example!

Input

Output