← CTE

Spending above income x1.5: mass, EUR, 6 mo.: Feb–Jul 2025

Level: Middle100 XP

Instructions

Consider transactions on accounts in the currency EUR (accounts.currency) with tx_time on or after February 1, 2025 and strictly before August 1, 2025. A client's income is the sum of transactions with amount > 0, and spending is the sum of the absolute values of transactions with amount < 0 (that is, -sum(amount)); all such accounts of the client are taken. Find clients of the segment 'mass' who had both income and spending, and whose spending is strictly greater than their income, multiplied by 1.5. Output id, name, income and spend. 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