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
SQL for Purchase Within 24 Hours
00:00
5 left

SQL for Purchase Within 24 Hours

MediumSQL · PostgreSQL

Problem

Identify users who made a purchase within 24 hours of receiving a promotional text, ensuring you account for duplicate messages.

Use the provided Attentive-style user, promotional message, and purchase data. Treat the 24-hour boundary as inclusive and include only purchases after or at the message timestamp.

Output

  1. Return one row per qualifying user with user_id, user_name, and first_qualifying_purchase_at.
  2. Exclude users without a qualifying purchase and sort by user_id ascending.

Schema

users
ColumnTypeDescription
user_idPKINTUnique user identifier
user_nameVARCHAR(100)User display name
emailVARCHAR(255)User email address
promotional_messages
ColumnTypeDescription
message_idPKINTUnique message record identifier
user_idINTRecipient user identifier
campaign_codeVARCHAR(50)Promotional campaign identifier
sent_atTIMESTAMPTimestamp when the text was sent
message_typeVARCHAR(30)Message classification
purchases
ColumnTypeDescription
purchase_idPKINTUnique purchase identifier
user_idINTPurchasing user identifier
purchased_atTIMESTAMPTimestamp when the purchase occurred
amountDECIMAL(10,2)Purchase amount
Tablesuserspromotional_messagespurchases
Interviewer

Your question is SQL for Purchase Within 24 Hours. 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.