Sign in to run and submit your work
Reading is open to everyone. Running code and saving drafts need an account so your work is yours and comes back on your next visit.
or
CODE WORKSPACE
For active (not soft-deleted) customers, return customer_id and country_bucket, where country_bucket is the country or the text 'unknown' when the country is missing. Order by customer_id.
Result columns · in this order
customer_idcountry_bucketHow to approach it
Filter deleted_at IS NULL, then wrap country in COALESCE(country, 'unknown') and alias it country_bucket.
Sample input
| customer_id | country | deleted_at |
|---|---|---|
| 1 | US | null |
| 2 | null | null |
| 3 | GB | null |
| 4 | IN | null |
| 5 | US | 2026-01-20 |
| 6 | GB | null |
6 rows — all rows shown.
Expected output
| customer_id | country_bucket |
|---|---|
| 1 | US |
| 2 | unknown |
| 3 | GB |
| 4 | IN |
| 6 | GB |
5 rows — all rows shown.
Constraints
Active means deleted_at IS NULL. Replace a missing country with COALESCE(country, 'unknown'). Do not use country = NULL.
Expected skills
Testing for missing values with IS NULL and substituting defaults with COALESCE.
Submit for review to find out what your query gets right, what it gets wrong, and how it compares with the best working query for this exercise.
This scenario runs a full workspace — editor, canvas and results side by side. It needs a laptop or desktop to be usable. Open this page on a bigger screen to start building.