How would you write a query to find the top three most expensive projects in each region using a window function?
Use the provided regions, projects, and project_expenses tables. Treat a project’s total cost as the sum of its expense amounts, with projects having no expenses treated as zero.
Output
- One row per selected project, with
region_name, project_id, project_name, total_cost, and region_rank
- Include up to three projects per region, ordered by total cost descending
- Break cost ties by
project_id ascending, and sort final results by region_name, then region_rank