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 cohort_day, day_offset, and active_buyers. day_offset is the integer day difference between activity_day and cohort_day.
Result columns · in this order
cohort_dayday_offsetactive_buyersHow to approach it
Create first_order and activity_days CTEs before grouping.
Sample input
| buyer_id | created_at |
|---|---|
| 1 | 2026-01-12 08:40:00 |
| 1 | 2026-01-15 14:20:00 |
| 3 | 2026-01-12 10:02:00 |
| 3 | 2026-01-22 14:46:00 |
4 rows — all rows shown.
Expected output
| cohort_day | day_offset | active_buyers |
|---|---|---|
| 2026-01-12 | 0 | 2 |
| 2026-01-12 | 3 | 1 |
| 2026-01-12 | 10 | 1 |
3 rows — all rows shown.
Constraints
Find each buyer's first order date, join to distinct activity days, count distinct buyers, and order by cohort_day, day_offset.
Expected skills
Cohort grain, date offsets, and distinct counting.
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.