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
A regional report lists customers by region. Customers with no region belong at the bottom of the list, not the top, and the order must be identical every time the report runs. Return all five customers in that order.
Result columns · in this order
customer_id | The customer. |
full_name | Their name. |
region | Their region, or 'unassigned'. |
How to approach it
Sort on a flag you compute yourself rather than relying on how this engine happens to place NULLs.
Sample input
| customer_id | full_name | region | signed_up_on |
|---|---|---|---|
| c1 | Ada Okafor | North | 2025-11-02 |
| c2 | Bo Lindqvist | null | 2025-12-14 |
| c3 | Chen Wei | South | 2026-01-03 |
| c4 | Dara O'Neill | North | 2026-01-20 |
| c5 | Eve Marsh | null | 2026-02-01 |
5 rows — all rows shown.
Expected output
| customer_id | full_name | region |
|---|---|---|
| c1 | Ada Okafor | North |
| c4 | Dara O'Neill | North |
| c3 | Chen Wei | South |
| c2 | Bo Lindqvist | unassigned |
| c5 | Eve Marsh | unassigned |
5 rows — all rows shown.
Constraints
unassigned.North; their relative order must be stable, so break the tie on customer_id.unassigned label itself — that only works by accident of the alphabet.Worked example
ORDER BY region alone puts c2 and c5 first, because SQLite sorts NULLs before every value. Other engines disagree: PostgreSQL puts them last by default, and NULLS FIRST / NULLS LAST is not available everywhere.
Sorting on CASE WHEN region IS NULL THEN 1 ELSE 0 END first makes the intent explicit and behaves the same on every engine.
What this tests
That NULL ordering is engine-defined rather than standard, and that a sort without a tie-break is not reproducible.
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.