TASK #220 · Hard · BBVABalance by Product Type
Your brief
The current balance of an account is start_balance plus received transfers
(transfers.to_account_id), minus sent transfers
(transfers.from_account_id) and card payments (card_payments). For an
account without operations it equals start_balance.
Write a query that, for each product type, returns product, the number of accounts accounts_count, the sum of current balances total_balance and the average current balance per account avg_balance. Round total_balance and avg_balance to two decimals.
Write a query that, for each product type, returns product, the number of accounts accounts_count, the sum of current balances total_balance and the average current balance per account avg_balance. Round total_balance and avg_balance to two decimals.
Ctrl / ⌘ + ↵
Result
Write a query and run it to see the results.
Schema
customerscustomer_id, full_name, city, joined_dateaccountsaccount_id, customer_id, product, opened_date, start_balancecard_paymentspayment_id, account_id, paid_at, merchant, category, amounttransferstransfer_id, from_account_id, to_account_id, transfer_at, amount, concept