You are given commercial lending data and asked to write a SQL query that returns the top 5 commercial clients by total loan volume, excluding any client marked with a high-risk flag. Use the client-level risk status to filter out ineligible clients, then aggregate funded loan amounts across each remaining client.
| Column | Type | Description |
|---|---|---|
| client_idPK | INT | Unique identifier for each client |
| client_name | VARCHAR(100) | Commercial or retail client name |
| client_type | VARCHAR(30) | Client segment such as Commercial or Retail |
| Column | Type | Description |
|---|---|---|
| client_id | INT | References the client |
| high_risk_flag | BOOLEAN | Whether the client is currently marked high risk |
| review_date | DATE | Date of the risk review |
| Column | Type | Description |
|---|---|---|
| loan_idPK | INT | Unique identifier for each loan |
| client_id | INT | References the borrowing client |
| loan_amount | DECIMAL(14,2) | Funded or requested loan amount |
| loan_status | VARCHAR(30) | Loan status such as Funded, Pending, or Cancelled |