Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 feedbackSuccess 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 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.