RBC branch operations wants to identify the highest-balance active accounts at each branch. Write a PostgreSQL query that joins account records to RBC branches and ranks eligible accounts within each branch using a window function.
status is Active and whose current_balance is not NULL.RANK() with PARTITION BY branch_id, ordering balances from highest to lowest.| Column | Type | Description |
|---|---|---|
| branch_idPK | INTEGER | Unique RBC branch identifier |
| branch_name | VARCHAR(100) | RBC branch name |
| province | VARCHAR(50) | Canadian province containing the branch |
| Column | Type | Description |
|---|---|---|
| account_idPK | INTEGER | Unique account identifier |
| branch_id | INTEGER | RBC branch associated with the account |
| account_type | VARCHAR(30) | Account product type |
| status | VARCHAR(20) | Current account status |
| current_balance | NUMERIC(12,2) | Current balance of the account |