Skip to content

Money in and money out per savings account

MediumFull bankConditional aggregationJoinsDates and time14 min2 hidden datasets

The task

Risk wants a February 2025 cash-flow summary for every savings account.

In transactions, a positive amount is money in and a negative amount is money out. Use transactions posted from 2025-02-01 00:00:00 up to but not including 2025-03-01 00:00:00.

Return one row for every account in accounts whose account_type is savings, including accounts with no transactions in February, with:

  • account_id
  • money_in: sum of the positive amounts, 0 if none
  • money_out: sum of the negative amounts shown as a positive number, 0 if none
  • net: money_in minus money_out

Sort by account_id ascending.

Expected output

account_idmoney_inmoney_outnet
  • Sorted by 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