← Window functions

'shopping' transaction series: <= 30 min, Feb–Jul 2025

Level: Middle100 XP

Instructions

For each transaction find the previous transaction of the same account (of any category; ordered by tx_time, ties by id). Output the transactions of the category 'shopping' with tx_time on or after February 1, 2025 and strictly before August 1, 2025 that happened no later than 30 min after the account's previous transaction (inclusive; compare the exact interval, not the rounded value). The first transaction of an account has no previous one and is not output. Columns: id, account_id, tx_time, amount and minutes_since_prev, the number of minutes since the previous transaction, rounded to 1 decimal place. Sort by the exact interval since the previous transaction ascending, then by id ascending.

Hints

Each next one is more detailed and costs more

Log in to open hints

Query

Result

Click Run to see the query result, or Check to submit your solution.

Dataset schema

accounts.client_id (0…N) ↔ clients.id (1…1)transactions.account_id (0…N) ↔ accounts.id (1…1)accountsPKidintegerFKclient_idintegerclientsPKidintegertransactionsPKidintegerFKaccount_idinteger
Exactly oneZero or oneZero or more
Table relationships
  • N:1Many-to-oneaccounts.client_id → clients.id
  • N:1Many-to-onetransactions.account_id → accounts.id

Table data

PostgreSQL

Select a table in the diagram or list to view its rows.

Dataset schema