Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rolling Five-Minute Transaction Threshold

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

Your question is Rolling Five-Minute Transaction Threshold. Start with the requirements and the one table 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

NICE Actimize monitors transaction activity for rapid bursts that may indicate suspicious behavior. Write a PostgreSQL query to identify users who exceed three transactions in any inclusive rolling five-minute window.

Requirements

  1. Partition activity by user_id and order it by transaction_ts.
  2. Count transactions from the current timestamp through the preceding five minutes, including both boundaries.
  3. Return only users whose maximum window count is greater than three.
  4. Include the earliest timestamp where the threshold was exceeded and the maximum transaction count observed.
  5. Ignore rows with a missing user_id or transaction_ts, and sort results by user_id.

Schema

customer_transactions
ColumnTypeDescription
transaction_idPKBIGINTUnique transaction identifier
user_idBIGINTCustomer or account identifier
transaction_tsTIMESTAMPTZTimestamp when the transaction occurred
amountNUMERIC(12,2)Transaction amount
Tablescustomer_transactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results