Write a SQL query using window functions to rank LendingClub customers by total loan amount within each state and return the top 3 per state.
Use the provided LendingClub customer and loan data. Include customers with at least one loan and exclude loans that do not match a customer.
state, customer_id, customer_name, total_loan_amount, and customer_rankstate, then customer_rank, then customer_id| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Unique LendingClub customer identifier |
| customer_name | VARCHAR(100) | Customer's full name |
| state | CHAR(2) | Two-letter US state abbreviation |
| Column | Type | Description |
|---|---|---|
| loan_idPK | INT | Unique loan identifier |
| customer_id | INT | Customer associated with the loan |
| loan_amount | NUMERIC(12,2) | Original principal amount of the loan |