Welcome to the SQL screen.
The question is on your right: 30-Day Moving Average of Bookings. Read through the requirements and the two tables first.
Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?
You’re on the analytics engineering team at a two-sided logistics marketplace (think “Uber for warehouse labor”) that processes ~2M task bookings per month across multiple metro areas. Operations leaders track booking volume to forecast staffing needs and to detect demand shocks (weather events, promotions, large enterprise contracts). Daily booking counts are noisy, so the team uses a 30-day moving average as the primary trend metric in dashboards.
Bookings are stored at the event level (one row per booking). However, the dashboard needs a daily time series that includes days with zero bookings (e.g., holidays or system outages), because missing dates can make the moving average misleading.
Write a SQL query to compute the daily booking count and the 30-day moving average of daily bookings.
2024-01-01 and 2024-01-07 (inclusive) using the dim_dates table.booked_at (treat booked_at as UTC).ma_30d_bookings as the average of daily_bookings over the current day and the prior 29 days (a 30-day trailing window).dt, daily_bookings, ma_30d_bookings.dt ascending.| Column | Type | Description |
|---|---|---|
| dtPK | DATE | Calendar date (one row per day) |
| Column | Type | Description |
|---|---|---|
| booking_idPK | BIGINT | Unique booking identifier |
| task_id | BIGINT | Task being booked |
| booked_at | TIMESTAMP | Timestamp when the booking was created (UTC) |
| status | VARCHAR(20) | Booking state (e.g., confirmed, cancelled) |