Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.