Write a SQL query to analyze branch operations performance by joining transactions, employees, and branch tables, then aggregating key metrics by month at U.S. Bank.
Use completed transactions only. Return monthly metrics for branches with matching employee and transaction records.
Output
- One row per branch and calendar month
- Columns:
branch_name, month, transaction_count, employees_involved, total_amount, average_amount, high_value_transactions
- Include completed transactions with null amounts in the transaction count, but exclude null amounts from amount aggregates
- Order by month ascending, then branch name ascending
Output details
- Format
month as YYYY-MM.
- Count distinct employees in
employees_involved.
- Round
average_amount to two decimal places.
- Return
total_amount as 0 when all amounts are NULL.
- Leave
average_amount as NULL when all amounts are NULL.
- Count high-value transactions where
amount is at least 1000.