GROUP BY a TEXT column with a trailing-space defensive TRIM
Comp committee meets Friday. Pull the top 10 LOs by funded count from the last 6 months — `funded_date >= '2025-11-01'`. Two columns: `lo_name`, `origination_count`. Sort by count descending, name ascending for tie-breaks. Heads up — the data quality team flagged a trailing-space issue on `lo_name`. Sarah Chen's record sometimes has a trailing space and her counts get split across two rows. TRIM the names so her totals consolidate before the comp grid sees this.
| Column | Type | Key |
|---|---|---|
| origination_id | INT | PK |
| app_id | INT | FK → lending_applications |
| account_id | INT | FK → retail_accounts |
| funded_date | TEXT | |
| funded_amount | REAL | |
| term_months | INT | |
| interest_rate | REAL | |
| rate_type | TEXT | |
| arm_reset_date | TEXT | |
| fico_at_orig | INT | |
| dti_at_orig | REAL | |
| ltv_at_orig | REAL | |
| property_value | REAL | |
| lo_name | TEXT | |
| channel | TEXT | |
| current_status | TEXT | |
| closed_date | TEXT |
Each hint you reveal reduces the XP you can earn. Try the query first.
Date filter on `funded_date` for the 6-month window, GROUP BY the LO, count and Top-N — standard rollup shape.
Trailing-space gotcha: identical-looking names with and without trailing whitespace group separately. Apply a string-trim function to the column in BOTH the SELECT projection AND the GROUP BY so the rows merge into one count.
Two-key sort (count desc, name asc) and a row cap at the comp committee's review window. If the count comes back at 11 rows, the trim isn't applied consistently across both clauses.