← Top-N per group

4 largest transactions: Казань, premium, Jun–Nov 2025

Level: Middle100 XP

Instructions

For each client from the city 'Казань' with the segment 'premium' output their 4 largest transactions by absolute amount: transactions (transactions) across all their accounts with tx_time on or after June 1, 2025 and strictly before December 1, 2025, both spending (amount < 0) and income (amount > 0); the larger |amount|, the larger the transaction; for equal |amount| take the transaction with the smaller id. If a client has fewer than 4 such transactions, output all of them; clients without transactions in this period are not in the result. Columns: client_id, name (the client's name), tx_id (the transaction id), amount (signed), category. Row order does not matter.

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