← Dates and time series

Open USD accounts aged 3+ months on June 30, 2025

Level: Middle100 XP

Instructions

Consider accounts in currency 'USD' (accounts.currency) that had not yet been closed on June 30, 2025 (closed_at is empty or strictly later than that date). An account's age on that date is the number of full months between opened_at and that date (age(June 30, 2025, opened_at): years * 12 + months). Keep accounts aged at least 3 months (so accounts opened after that date drop out). Group by account type (accounts.type) and output type, accounts_cnt, the number of accounts, avg_months, the average age in months (rounded to 1 decimal place), and max_months, the greatest age. 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