Transactions Within Five Minutes
Problem statement
Find every pair of transactions made by the same customer no more than five minutes apart.
Orient each pair chronologically. When timestamps are equal, the smaller transaction ID comes first. Return the elapsed whole seconds and do not emit mirrored or self-pairs.
Table schema
MySQLPostgreSQLPandas
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
transactions
| Column | Type | Nullable | Description |
|---|---|---|---|
| transaction_idPK | Integer | No | — |
| customer_id | Integer | No | — |
| transaction_time | Timestamp | No | — |
| transaction_amount | Decimal | No | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| customer_id | Integer | No | — |
| first_transaction_id | Integer | No | — |
| second_transaction_id | Integer | No | — |
| seconds_apart | Integer | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
- Five minutes means at most 300 seconds, inclusive.
- Pairs must belong to one customer.
- Return all qualifying pairs, not only adjacent transactions.