Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Second Purchase Within 24 Hours

Easy
EasySQL & Data ManipulationAsked 1 times

Problem

On Meta Marketplace, the analytics team wants to identify users whose second completed transaction happened within 24 hours of their first completed transaction.

Write a SQL query to return the users who meet this condition.

Requirements

  1. Consider only rows where status = 'completed'.
  2. For each user, identify their first and second completed transactions by transaction_time.
  3. Return only users whose second completed transaction occurred within 24 hours of their first.
  4. Output user_id, first_transaction_time, second_transaction_time, and the time difference as hours_between.
  5. Order the final result by user_id.

Schema

marketplace_transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
user_idINTMeta user identifier
transaction_timeTIMESTAMPTimestamp when the transaction occurred
amountDECIMAL(10,2)Transaction amount
statusVARCHAR(20)Transaction status such as completed, failed, pending, or refunded
payment_methodVARCHAR(30)Payment method used for the transaction
Practicing as: Data Analyst interview at Meta

Hi, I'll play your Meta interviewer for the Data Analyst role. Candidates describe these interviews as mostly positive and moderately difficult, so expect me to be friendly and conversational. Take your time with the question above and answer like we're in the room.

Take this as a live interview session →

You are practicing as a guest. Sign up free to run your code against the sample data. Your draft stays right here.

Sign up freeI have an account
SELECT ...
FROM ...
JOIN ... ON ...
GROUP BY ...
HAVING ...
ORDER BY ... DESC;
Sign up to unlock solutions
Meta Data Analyst Interview Questions
Next questions
MetaSecond Most Recent Marketplace PurchaseHardMetaSecond-Highest Marketplace Transactions UserMediumSquarespaceFirst Purchase Within 24 HoursMedium