The 'first-ever order' part is straightforward once you think MIN(order_date) grouped by user, but I initially forgot I needed to join that back against the date spine and almost counted repeat buyers.
Start by generating a complete date spine for the last 7 days using a recursive CTE or a calendar table, then left join aggregated daily metrics to it. Compute DAU from session events, new buyers from first-order dates, and finally calculate conversion rate with proper zero handling and rounding.
Pro tip: Explicitly state your assumptions about the database (e.g., date functions, session event definition) and mention that you'd validate the query against edge cases like zero DAU days and timezone boundaries—this shows production-level thinking.
Create a list of the last 7 days (including today) using a recursive CTE or a calendar table to ensure all dates appear, even with no activity.
Count distinct users from session events per day, filtering to the last 7 days, and group by date.
Find each user's first order date (using MIN(order_date) per user), then count users whose first order falls on each of the last 7 days.
Left join the date spine with DAU and new buyers aggregates, then calculate conversion rate as new_buyers / NULLIF(dau, 0), rounded to 2 decimals, defaulting to 0.00 when DAU is zero.
Select the date, DAU, new buyers, and conversion rate columns, ensuring proper ordering by date and handling any NULLs from the left joins.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.