Repeated Payment Transactions
Stripe 🧠 Hard SQL
Beginner Mode

Objective

You are given a table of credit card transactions. Each row represents a single payment with details about the merchant, credit card, amount, and timestamp.

Table Schema:

The transactions table:

Column Type Description
transaction_id integer Unique ID for each transaction
merchant_id integer ID of the merchant
credit_card_id integer ID of the credit card used
amount decimal Payment amount in dollars
transaction_timestamp timestamp Date and time of the transaction

Task Requirements:

  • Identify transactions that occur at the same merchant, with the same credit card and same amount, within 10 minutes of the previous matching transaction
  • Count the number of such repeated payments, ignoring the first transaction in each sequence
  • Use the LAG() window function partitioned by merchant, credit card, and amount



Output columns: payment_count

Examples

Example 1:

Input:

transactions
amountcredit_card_idmerchant_idtransaction_idtransaction_timestamp
501112025-01-15 10:00:00
501122025-01-15 10:08:00
501132025-01-15 10:30:00
1002242025-01-15 11:00:00
1002252025-01-15 11:05:00
502162025-01-15 12:00:00
751172025-01-15 10:05:00

Output:
payment_count
2
Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →