Write SQL to rank customers by loan amount within each branch.
Calculate each customer's total non-null loan amount and assign the same rank to customers tied at the same amount. Include only customers with at least one non-null loan associated with a branch.
branch_name, customer_id, customer_name, total_loan_amount, and branch_rank.| Column | Type | Description |
|---|---|---|
| branch_idPK | INT | Unique branch identifier |
| branch_name | VARCHAR(100) | Branch name |
| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Unique customer identifier |
| customer_name | VARCHAR(150) | Customer full name |
| branch_id | INT | Branch assigned to the customer |
| Column | Type | Description |
|---|---|---|
| loan_idPK | INT | Unique loan identifier |
| customer_id | INT | Customer receiving the loan |
| loan_amount | NUMERIC(12,2) | Loan principal amount |