Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL for Sudden Transaction Drops
00:00
5 left

SQL for Sudden Transaction Drops

MediumSQL · PostgreSQL

Problem

Write a query to identify users who have experienced a sudden drop in transaction frequency over the last 30 days compared to their historical average at Stripe.

Use April 2025 as the last 30-day period and January through March 2025 as the historical period. Consider only successful transactions. A user qualifies when their recent count is less than 50% of their historical average 30-day count and they have at least one historical transaction.

Output

  1. One row per qualifying user with user_id, email, recent_transaction_count, historical_avg_30_day_count, and drop_ratio
  2. Order by drop_ratio ascending, then user_id ascending

Schema

users
ColumnTypeDescription
user_idPKINTUnique Stripe user identifier
emailVARCHAR(255)User email address
transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
user_idINTUser who initiated the transaction
transaction_dateDATETransaction processing date
statusVARCHAR(20)Transaction outcome, such as succeeded or failed
amountNUMERIC(12,2)Transaction amount in USD
Tablesuserstransactions
Interviewer

Your question is SQL for Sudden Transaction Drops. Start with the requirements and the two 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.