Aggregate and Join Across Tables

Problem

Given orders(id, user_id, amount) and users(id, country), write SQL for total spend per country, then the top spender per country.

Example

SELECT country, SUM(amount) ... GROUP BY country

Constraints

  • Use window functions for the per-country top spender

Note

Explain index/JOIN trade-offs.

added …
LeaderboardSalaryAccount