Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Attribution: Clicked But Not Purchased
00:00
5 left

Attribution: Clicked But Not Purchased

HardSQL · PostgreSQL

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
Interviewer

Your question is Attribution: Clicked But Not Purchased. Start with the requirements and the three tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.