Bank Account Balance

ASKED IN INTERVIEW
2pts
Fintech

Problem Statement

A fintech startup needs to display the current net balance for all users. The ledger records every transaction: credits are stored as positive numbers and debits are stored as negative numbers.

Your task is to write a query that calculates the final balance for each account.

Rules:

  • Final balance is the sum of all transaction amounts for that account.
  • Output columns: account_id, account_name, final_balance.
  • Results must be sorted by account_id in ascending order.
Tests your understanding of
Aggregation, Arithmetic and Grouping

Input Tables

transactions
transaction_id(INTEGER)account_id(INTEGER)amount(DECIMAL)transaction_date(DATE)
110015002026-01-01
21001-2002026-01-02
3100210002026-01-01
410011502026-01-05
51002-11002026-01-10
accounts
account_id(INTEGER)account_name(VARCHAR)account_type(VARCHAR)
1001Alice GreenSavings
1002Bob WhiteChecking
branches
branch_id(INTEGER)branch_name(VARCHAR)
1Downtown
2Uptown

Expected Output

account_id(INTEGER)account_name(VARCHAR)final_balance(DECIMAL)
1001Alice Green450
1002Bob White-100

Tags

EasyASKED IN INTERVIEWAggregationArithmeticGrouping
10-15 min
88%

Hints