IS NULL + date comparison to catch stale and missing KYC together
Annual KYC refresh review. Return every customer whose `last_kyc_refresh` is NULL (never refreshed) OR older than 2023-04-24 (3+ years stale as of today). One row per customer: `customer_id`, `last_kyc_refresh`. Order by `last_kyc_refresh NULLS FIRST, customer_id`. This is what the examiners ask for first, every time.
| Column | Type | Key |
|---|---|---|
| customer_id | INT | PK |
| first_name | TEXT | |
| last_name | TEXT | |
| date_of_birth | TEXT | |
| TEXT | ||
| phone | TEXT | |
| state | TEXT | |
| status | TEXT | |
| onboarded_date | TEXT | |
| last_kyc_refresh | TEXT |
Each hint you reveal reduces the XP you can earn. Try the query first.
`last_kyc_refresh` is stored as a TEXT date (`YYYY-MM-DD`). String comparison works correctly because the format is lexicographically-sortable — `'2023-01-27' < '2023-04-24'` is true.
Two conditions OR'd together: `last_kyc_refresh IS NULL OR last_kyc_refresh < '2023-04-24'`. The order matters for sort, but not for the filter itself.
Output covers both populations in one set: NULL refresh dates AND dates older than the cutoff. Order by last_kyc_refresh so NULLs and the oldest stale dates land together at the top.