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
Return issue_type, customer_key, and rows_in_batch for duplicate and null customer_id values in customer_stage.
Result columns · in this order
issue_typecustomer_keyrows_in_batchHow to approach it
Use GROUP BY/HAVING for duplicate keys and a separate null-key branch with UNION ALL.
Sample input
| customer_id | updated_at | |
|---|---|---|
| 104 | dee-old@example.com | 2026-03-05 09:00:00 |
| 104 | dee@example.com | 2026-03-05 12:30:00 |
| null | ghost@example.com | 2026-03-05 13:00:00 |
3 rows — all rows shown.
Expected output
| issue_type | customer_key | rows_in_batch |
|---|---|---|
| duplicate_key | 104 | 2 |
| null_key | <NULL> | 1 |
2 rows — all rows shown.
Constraints
Label duplicate keys as duplicate_key and null keys as null_key. Cast non-null customer_id to text. Use '<NULL>' for the null key bucket. Order by issue_type, then customer_key.
Expected skills
Unique-key preflight checks before upserts and MERGE statements.
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.