How would you identify the top 5% of loan applicants based on their credit score within each state at American Credit Acceptance?
Write a SQL query using the provided applicant, application, and state reference data. Exclude applicants without a credit score and include applicants whose score meets or exceeds their state's 95th percentile cutoff.
Output
- One row per qualifying applicant, with
applicant_id, applicant_name, state_code, state_name, credit_score, state_percentile_cutoff, and state_rank.
- Sort by
state_code, descending credit_score, then applicant_id.
Output details
- Use continuous 95th-percentile interpolation within each
state_code and round state_percentile_cutoff to two decimal places.
- Assign
state_rank using descending credit_score, with tied scores sharing ranks and subsequent ranks skipped.
- Sort tied
credit_score rows by applicant_id ascending.