Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Attribution: Clicked But Not Purchased

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

Your question is Attribution: Clicked But Not Purchased. Start with the requirements and the three 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

Asana Spa's marketing team wants to identify users who clicked an ad but did not complete a purchase within seven days of any recorded click. Write a PostgreSQL query that returns these users for campaign follow-up.

Requirements

  1. Consider every ad click and match purchases by the same user.
  2. Treat a purchase from the click timestamp through exactly seven days afterward as a conversion.
  3. Return users with at least one click and no purchase in any of their seven-day click windows.
  4. Include the user's email and earliest ad click timestamp, ordered by user_id.

Schema

users
ColumnTypeDescription
user_idPKINTUnique Asana Spa user identifier
emailVARCHAR(255)User email address
ad_clicks
ColumnTypeDescription
click_idPKINTUnique ad click identifier
user_idINTUser who clicked the advertisement
campaign_nameVARCHAR(100)Asana Spa marketing campaign name
clicked_atTIMESTAMPTimestamp when the ad was clicked
purchases
ColumnTypeDescription
purchase_idPKINTUnique purchase identifier
user_idINTUser who completed the purchase
purchased_atTIMESTAMPTimestamp when the purchase was completed
amountDECIMAL(10,2)Purchase amount
Tablesusersad_clickspurchases
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results