Both sides of every transaction
SQLMedium11 min
Your task
Return each transaction with the accounts it touched. Give txn_id, account and amount_cents, ordered by transaction then account.
Tables
ledger_account| idINTEGER | nameTEXT | kindTEXT |
|---|
| 1 | Cash | asset |
| 2 | Revenue | income |
| 3 | Fees | expense |
| 4 | Refunds | expense |
entry| idINTEGER | txn_idINTEGER | account_idINTEGER | amount_centsINTEGER | booked_onTEXT |
|---|
| 1 | 100 | 1 | 50000 | 2026-01-05 |
| 2 | 100 | 2 | -50000 | 2026-01-05 |
| 3 | 101 | 1 | -1500 | 2026-01-05 |
| 4 | 101 | 3 | 1500 | 2026-01-05 |
| 5 | 102 | 1 | 32000 | 2026-02-09 |
| 6 | 102 | 2 | -32000 | 2026-02-09 |
More rows not shown Model answerRun