RienSQL
TASK #222 · Medium · Santander

Second-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.
Expected columnscustomer_id full_name second_largestSantander
SQL editor
SQLite
Ctrl / ⌘ + ↵
Result

Write a query and run it to see the results.

Schema
customerscustomer_id, full_name, city
accountsaccount_id, customer_id, account_type, balance, overdraft_limit
transactionstransaction_id, account_id, tx_date, tx_type, amount, description