Find cards with more than 5 transactions in a 10-minute window

Quick Overview

Write a SQL query that finds payment cards with more than five transactions inside a 10-minute window measured from any of the card's own transactions. It tests self-joins or range-framed window functions, inclusive time boundaries, and counting the anchor row correctly.

Find cards with more than 5 transactions in a 10-minute window

Company: Adyen

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

A card is high-velocity if, for some transaction on that card, more than 5 transactions on the same card (including that transaction itself) occur within 10 minutes from that transaction's timestamp. Write a query that returns the distinct `card_id` values of all high-velocity cards, ordered by `card_id` ascending. ```hint Counting per transaction Treat each transaction as the start of its own 10-minute window and work out how many rows on the same card fall inside it. You need to compare rows of the table with other rows of the same table. ``` ### Input Table(s) `transactions` | Column | Type | Meaning | |---|---|---| | transaction_id | INT | Unique id of the transaction | | card_id | INT | Card used for the transaction, NOT NULL | | amount | DECIMAL(10,2) | Transaction amount, NOT NULL | | transaction_time | DATETIME (TIMESTAMP in PostgreSQL) | When the transaction happened, NOT NULL | Primary key: `transaction_id`. ### Output Contract - One column: `card_id`. - One row per high-velocity card, with no repeated card ids. - Rows ordered by `card_id` ascending. Each `card_id` appears once, so the order is fully determined. - There are no computed numeric columns, so no rounding applies. ### Example `transactions` | transaction_id | card_id | amount | transaction_time | |---|---|---|---| | 1 | 7 | 12.50 | 2024-03-01 09:00:00 | | 2 | 7 | 8.00 | 2024-03-01 09:02:00 | | 3 | 7 | 15.25 | 2024-03-01 09:04:00 | | 4 | 7 | 3.99 | 2024-03-01 09:06:00 | | 5 | 7 | 20.00 | 2024-03-01 09:08:00 | | 6 | 7 | 9.10 | 2024-03-01 09:10:00 | | 7 | 9 | 40.00 | 2024-03-01 10:00:00 | | 8 | 9 | 5.00 | 2024-03-01 10:01:00 | | 9 | 9 | 5.00 | 2024-03-01 10:02:00 | | 10 | 9 | 5.00 | 2024-03-01 10:03:00 | | 11 | 9 | 5.00 | 2024-03-01 10:04:00 | | 12 | 9 | 60.00 | 2024-03-01 10:10:01 | Expected result: | card_id | |---| | 7 | Card 7 qualifies: the window that starts at transaction 1 (09:00:00) runs to 09:10:00 inclusive and holds transactions 1 to 6, which is 6 transactions. Card 9 does not: the window starting at 10:00:00 ends at 10:10:00 and holds 5 transactions (transaction 12 is one second late), the window starting at 10:01:00 holds transactions 8 to 12, which is also 5, and every later window holds fewer. ### Constraints and Clarifications - `transactions` has between 1 and 10,000 rows. - `card_id` is a positive integer. - The window for a transaction at time `t` runs from `t` to `t + 10 minutes`, inclusive on both ends. A transaction exactly 10 minutes after the anchor counts; one at 10 minutes and 1 second does not. - "More than 5" means at least 6 transactions in one window, with the anchor transaction counted. - No column can be NULL, and `transaction_id` is unique, so every row is a separate transaction. - Several transactions on the same card can share a timestamp. Each of them counts toward the window. - `amount` plays no part in the rule.

Overview: Write a SQL query that finds payment cards with more than five transactions inside a 10-minute window measured from any of the card's own transactions. It tests self-joins or range-framed window functions, inclusive time boundaries, and counting the anchor row correctly.

Adyen logo
Adyen
Nov 25, 2026
mediumData ScientistOtherData Manipulation (SQL/Python)
0
0

A card is high-velocity if, for some transaction on that card, more than 5 transactions on the same card (including that transaction itself) occur within 10 minutes from that transaction's timestamp. Write a query that returns the distinct card_id values of all high-velocity cards, ordered by card_id ascending.

Input Table(s)

transactions

ColumnTypeMeaning
transaction_idINTUnique id of the transaction
card_idINTCard used for the transaction, NOT NULL
amountDECIMAL(10,2)Transaction amount, NOT NULL
transaction_timeDATETIME (TIMESTAMP in PostgreSQL)When the transaction happened, NOT NULL

Primary key: transaction_id.

Output Contract

  • One column: card_id .
  • One row per high-velocity card, with no repeated card ids.
  • Rows ordered by card_id ascending. Each card_id appears once, so the order is fully determined.
  • There are no computed numeric columns, so no rounding applies.

Example

transactions

transaction_idcard_idamounttransaction_time
1712.502024-03-01 09:00:00
278.002024-03-01 09:02:00
3715.252024-03-01 09:04:00
473.992024-03-01 09:06:00
5720.002024-03-01 09:08:00
679.102024-03-01 09:10:00
7940.002024-03-01 10:00:00
895.002024-03-01 10:01:00
995.002024-03-01 10:02:00
1095.002024-03-01 10:03:00
1195.002024-03-01 10:04:00
12960.002024-03-01 10:10:01

Expected result:

card_id
7

Card 7 qualifies: the window that starts at transaction 1 (09:00:00) runs to 09:10:00 inclusive and holds transactions 1 to 6, which is 6 transactions. Card 9 does not: the window starting at 10:00:00 ends at 10:10:00 and holds 5 transactions (transaction 12 is one second late), the window starting at 10:01:00 holds transactions 8 to 12, which is also 5, and every later window holds fewer.

Constraints and Clarifications

  • transactions has between 1 and 10,000 rows.
  • card_id is a positive integer.
  • The window for a transaction at time t runs from t to t + 10 minutes , inclusive on both ends. A transaction exactly 10 minutes after the anchor counts; one at 10 minutes and 1 second does not.
  • "More than 5" means at least 6 transactions in one window, with the anchor transaction counted.
  • No column can be NULL, and transaction_id is unique, so every row is a separate transaction.
  • Several transactions on the same card can share a timestamp. Each of them counts toward the window.
  • amount plays no part in the rule.