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
customers_snapshot is a dbt snapshot with dbt_valid_from and dbt_valid_to. Return customer_id, plan and dbt_valid_from for the row that was current on 2026-03-15. Order by customer_id.
Result columns · in this order
customer_id | Stable customer identifier. Appears once per version. |
plan | The plan that version of the customer was on. |
dbt_valid_from | When this version became true. Inclusive. |
How to approach it
Try WHERE dbt_valid_to IS NULL first and read the result. It answers a different question than the one you were asked.
Sample input
| customer_id | plan | dbt_valid_from | dbt_valid_to |
|---|---|---|---|
| 1 | free | 2026-01-10 | 2026-03-01 |
| 1 | pro | 2026-03-01 | 2026-04-02 |
| 1 | enterprise | 2026-04-02 | null |
| 2 | pro | 2026-02-14 | null |
| 3 | free | 2026-03-20 | null |
5 rows — all rows shown.
Expected output
| customer_id | plan | dbt_valid_from |
|---|---|---|
| 1 | pro | 2026-03-01 |
| 2 | pro | 2026-02-14 |
2 rows — all rows shown.
Constraints
A row is current at a moment when dbt_valid_from is on or before it AND dbt_valid_to is either after it or NULL. NULL means the row is still open. Order by customer_id.
Expected skills
Reading an SCD2 interval, why dbt_valid_to IS NULL only answers 'now', and the half-open interval that makes an as-of query correct.
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.