TASK #222 · Medium · SantanderSecond-Largest Charge per Customer
Your brief
Charges in transactions are the rows with tx_type = 'cargo'. A customer
can have several accounts.
Write a query that, for each customer, returns customer_id, full_name and the second-largest charge amount across all of their accounts second_largest. If the maximum amount repeats, the second-largest is the next smaller amount. Leave out customers with fewer than two different charge amounts.
Write a query that, for each customer, returns customer_id, full_name and the second-largest charge amount across all of their accounts second_largest. If the maximum amount repeats, the second-largest is the next smaller amount. Leave out customers with fewer than two different charge amounts.
Ctrl / ⌘ + ↵
Result
Write a query and run it to see the results.
Schema
customerscustomer_id, full_name, cityaccountsaccount_id, customer_id, account_type, balance, overdraft_limittransactionstransaction_id, account_id, tx_date, tx_type, amount, description