Write an advanced SQL query to aggregate transaction volumes, handle window functions, and efficiently stage data transformations.
Use the provided Brex card, merchant, and transaction tables. Include only settled USD transactions during Q1 2025.
Output
- One row per merchant and transaction month with
transaction_month, merchant_id, merchant_name, transaction_count, total_volume, and merchant_rank.
- Rank merchants within each month by descending total volume, with ties sharing a rank.
- Sort by
transaction_month, merchant_rank, and merchant_id.