The multi-trial-start rule is where I got tripped up.
Break the problem into sequential CTEs: first identify each user's earliest qualifying trial start within 7 days of assignment, then compute conversion status, then determine D30 retention by checking sessions in the 30-37 day window after trial start, and finally aggregate per variant. Use LEFT JOINs to preserve all assigned users and conditional aggregation for the metrics. Ensure the retention rate denominator is only converted users.
Pro tip: Explicitly state your assumptions about the data model (e.g., one assignment per user, session timestamps) and mention that you would validate edge cases like multiple trials or missing sessions before finalizing the query. This shows you think about data quality and metric definitions, which is crucial for A/B testing.
Join experiment assignments with trial starts on user_id, filter trials that started within 7 days after assignment, and use ROW_NUMBER() or MIN() to select the earliest trial start per user.
Flag users who have a qualifying trial start as converted; all assigned users should be included, with non-converters having NULL trial start.
For each converted user, check if they have at least one session between 30 and 37 days after their earliest trial start. Use a LEFT JOIN with sessions and a conditional flag.
Group by variant and calculate: COUNT(DISTINCT assigned users), COUNT(DISTINCT converted users), signup rate (converted/assigned), COUNT(DISTINCT retained users), and retention rate (retained/converted).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.