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
shop_orders.placed_at is a timestamp down to the second, not a date. The team wants a monthly trend from it.
Return one row per calendar month present in the data, with the month written as YYYY-MM, ordered by month.
Result columns · in this order
month | The calendar month, as YYYY-MM. |
orders | How many orders were placed that month. |
revenue | Total order value for the month. |
How to approach it
Derive the month from the timestamp and group by it. No date range is needed at all.
Sample input
| order_id | customer_id | placed_at | status | order_total |
|---|---|---|---|---|
| 1001 | c1 | 2026-01-05 10:00:00 | paid | 120 |
| 1002 | c2 | 2026-01-12 14:30:00 | Paid | 80 |
| 1003 | c1 | 2026-01-20 09:15:00 | pending | 45 |
| 1004 | c3 | 2026-01-31 23:30:00 | PAID | 200 |
| 1005 | c2 | 2026-02-01 00:15:00 | paid | 60 |
| 1006 | c4 | 2026-02-03 11:00:00 | paid | 150 |
| 1007 | c3 | 2026-02-10 16:45:00 | refunded | 90 |
| 1008 | c1 | 2026-02-14 12:00:00 | paid | 300 |
| 1009 | c5 | 2026-02-18 08:30:00 | Paid | 75 |
| 1010 | c4 | 2026-02-25 19:20:00 | pending | 85 |
| 1011 | c5 | 2026-02-28 21:00:00 | paid | 130 |
| 1012 | c2 | 2026-03-02 10:10:00 | paid | 95 |
12 rows — scroll inside the table to see them all.
Expected output
| month | orders | revenue |
|---|---|---|
| 2026-01 | 4 | 445 |
| 2026-02 | 7 | 890 |
| 2026-03 | 1 | 95 |
3 rows — all rows shown.
Constraints
month must be the 7-character YYYY-MM form so the months sort correctly as text.Worked example
Order 1004 was placed at 2026-01-31 23:30:00 and order 1005 at 2026-02-01 00:15:00. They belong to different months, 30 minutes apart.
A learner who filters January with placed_at BETWEEN '2026-01-01' AND '2026-01-31' loses order 1004 entirely: the bare date compares as 2026-01-31 00:00:00, which is before 23:30. January reads 3 orders and 245 instead of 4 and 445.
What this tests
That a timestamp is not a date: bucketing by the month part of the value rather than by a date range that silently excludes the last day.
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.