The join logic is straightforward but the window math trips you up if you're not careful.
Start by defining the user cohort and their signup date, then compute the number of transactions in the first 7 days and bucket users accordingly. Next, determine Day-30 retention by checking for any transaction between day 30 and day 37 post-signup, and finally aggregate retention rate per bucket.
Pro tip: Clarify the definition of 'day' (e.g., calendar day vs. 24-hour period) and ensure you handle time zones consistently; also consider using a LEFT JOIN to include users with zero transactions in the first 7 days.
Select all users with their signup date, ensuring you have a clear definition of the cohort (e.g., all users or a specific time range).
Join transactions to users and count transactions where transaction date is between signup date and signup date + 7 days. Use LEFT JOIN to include users with zero transactions.
Create buckets: 0, 1, 2, 3+ based on the count from step 2. Use a CASE statement to assign each user to a bucket.
For each user, check if they have at least one transaction between day 30 and day 37 post-signup. Use a LEFT JOIN or EXISTS subquery to flag retained users.
Group by bucket and calculate the retention rate as the number of retained users divided by total users in the bucket, multiplied by 100 for percentage.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.