Write a SQL query to analyze branch transaction volumes by region and month, joining branch, transaction, and customer tables to identify trends and outliers.
Use completed transactions from active branches and active customers. Treat a month as an outlier when its regional total amount exceeds twice that region's average monthly total amount.
Output
- One row per region and month, with
region, month, transaction_count, total_amount, average_amount, prior_month_count, percent_change, volume_rank, and volume_flag.
- Include all qualifying region-month rows, ordered by
region and month ascending. Rank higher transaction counts first, breaking ties with higher total amounts.