Wallet Balances After Transfers
Problem
A payments app gives each wallet a starting float. Every transfer moves money from one wallet to another. A wallet's balance is its starting float plus everything received minus everything sent.
Report, for each wallet, its current balance and whether it is **overdrawn** (balance below zero).
Return `wallet_id`, `holder`, `balance`, and `overdrawn` (the text `'Yes'` or `'No'`). Any order.
Tables
Example rows — the live problem includes the full dataset.
| wallet_id | holder | opening |
|---|---|---|
| 1 | Mireille | 100 |
| 2 | Tariq | 200 |
| 3 | Sven | 10000 |
| transfer_id | sender_id | receiver_id | amount | sent_on |
|---|---|---|---|---|
| 1 | 1 | 3 | 400 | 2021-08-01 |
| 2 | 3 | 2 | 500 | 2021-08-02 |
| 3 | 2 | 1 | 200 | 2021-08-03 |
Expected output
Your answer should return 4 rows with the columns wallet_id, holder, balance, overdrawn.
Starter code (SQL)
SELECT *
FROM wallets;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock