Skip to content

Busy accounts in May and the fees they paid

MediumFull bankGroup and aggregateConditional aggregationDates and time14 min2 hidden datasets

The task

The pricing team is reviewing fees on very active accounts. Look at transactions with posted_at on or after 2025-05-01 00:00:00 and before 2025-06-01 00:00:00.

An account is busy when it has at least 25 transactions in that window, in any category. For each busy account return:

  • account_id
  • transactions: its number of transactions in the window, in any category
  • fee_count: how many of them are in the category fees (0 if none)
  • fee_total: the fees turned into a positive amount (0 if none)

Sort by transactions descending, then account_id ascending.

Expected output

account_idtransactionsfee_countfee_total
  • Sorted by transactions descending, then account_id ascending.
  • Checked on the sample and on 2 hidden datasets. How grading works

Tables Digital bank · click a name to insert it

customers70 rows in the sample

One row per customer. Key: customer_id.

intUnique id.
textName.
dateDay they became a customer.
textretail, premium or business.
accounts126 rows in the sample

One row per account. A customer can have several. Key: account_id.

intUnique id.
intOwner.
textchecking, savings or credit.
dateOpening day.
dateClosing day. NULL while open.
transactions9,906 rows in the sample

One row per posted transaction. Positive amounts are money in, negative are money out. Key: txn_id.

bigintUnique id.
intThe account.
timestampWhen it posted (UTC).
numeric(12,2)Signed amount, USD.
textsalary, rent, groceries, dining, travel, transfer, fees or refund.
textMerchant name. NULL for salary, transfers and fees.

Related questions

Loading the editor and PostgreSQL