Again, scenario of a schema for which I needed to design the whole schema?
Design a normalized relational schema for accounts, customers, account ownership, and account transactions, then write a query that validates the design by producing an account-level balance report. Include accounts without transactions and preserve accounts with no recorded owner.
Output
- One row per account with
account_id, account_type, owner_names, balance, latest_transaction_date, and account_type_rank.
- Include every account, calculate credits as positive and debits or disbursements as negative, and use zero for accounts without transactions.
- Sort by
account_type, descending balance, then account_id.
Output details
- Sort
account_type ascending, balance descending with nulls last, and account_id ascending.
- Format
balance as numeric with exactly two decimal places.
- Set
latest_transaction_date to the maximum transaction date, or NULL when no transaction exists.
- Treat transaction types other than
credit, debit, and disbursement as contributing zero.
- Aggregate distinct owner names alphabetically, separated by
', ', and return NULL when no owner exists.
- Assign dense ranks within each
account_type, with equal balances sharing a rank.