You're a treasury analyst at a mobile neobank. The finance team is reconciling changes in the operating cash balance over a reporting period. The ledger_entries table contains individual credits and debits, while report_days specifies the dates that must appear in the report. Management needs to see both the daily net change and the balance accumulated since the beginning of the period.
For each date in report_days, calculate the net change: credit increases the balance, while debit decreases it. Exclude ledger entries on dates outside the reporting calendar. The balance before the first reporting date is 0.00.
Return these columns:
- report_date — the reporting date, formatted as YYYY-MM-DD;
- daily_net_usd — the net change for that date in USD, a numeric value with 2 decimal places;
- running_balance_usd — the accumulated balance from the first reporting date through the current date, inclusive, a numeric value with 2 decimal places.
Return exactly one row for each date in report_days. Sort the result by report_date in ascending order. Exclude NULL values in amount_usd from the sum. If a date has no ledger entries with known amounts, daily_net_usd must be 0.00. Include every individual ledger entry for a given date, even when amounts are identical, but aggregate them into a single daily row.
report_datedaily_net_usdrunning_balance_usdShowing the first 3 rows of the sample — the full sample comes with Premium
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign in