How would you write a query to find the top 3 highest-spending members within each client account using window functions?
Use the provided client account, member, and transaction data. Calculate each member's total transaction amount and use member_id as the deterministic tie-breaker.
Output
- One row per qualifying member, with
client_account_id, account_name, member_id, member_name, total_spent, and spending_rank
- Include only the top three members within each account
- Order by
client_account_id, then spending_rank