Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Flag Suspicious Card Transactions

HardSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Flag Suspicious Card Transactions. Start with the requirements and the three tables on the right.

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.

Problem

NovaPay wants to flag accounts with potentially fraudulent card activity. Write a SQL query to identify accounts that had at least 3 declined transactions within any 1-hour window on the same day.

Return only suspicious accounts and include the time window summary.

Requirements

  1. Consider only transactions where status = 'declined'.
  2. Group suspicious activity by account_id and calendar date.
  3. Return accounts where a 1-hour window contains at least 3 declined transactions.
  4. Output: account_id, customer_name, transaction_date, first_decline_time, last_decline_time, and declined_count.
  5. Order results by transaction_date ascending, then declined_count descending, then account_id.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer full name
risk_tierVARCHAR(20)Internal fraud risk tier
accounts
ColumnTypeDescription
account_idPKINTUnique account identifier
customer_idINTReferences customers.customer_id
account_statusVARCHAR(20)Current account status
opened_atDATEDate the account was opened
transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
account_idINTReferences accounts.account_id
merchant_nameVARCHAR(100)Merchant where the transaction occurred
transaction_tsTIMESTAMPTransaction timestamp
amountDECIMAL(10,2)Transaction amount
statusVARCHAR(20)Transaction status
Tablescustomersaccountstransactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results