Write a SQL query to find the top three medical claim categories by spend for each region, ranking them using a window function.
Use the provided claims, members, and claim categories data. Include only claims associated with a member and category, and treat missing spend as zero when calculating category totals.
Output
- One row per qualifying region and claim category, with
region, category_name, total_spend, and spend_rank.
- Include categories ranked 1 through 3 within each region, preserving ties.
- Order by
region, total_spend descending, and category_name.