The definitions sound clean until you start writing the CTEs and realize you need to be careful about what 'first-ever event' means across all of history, not just the two days in scope.
Start by clarifying the schema and definitions, then build CTEs to isolate active users on the target date and the day before, using first-ever event logic for new users. Finally, join these CTEs to compute new, retained, churned, and net users per platform, ensuring correct handling of edge cases like missing activity.
Pro tip: Always confirm the date boundaries and timezone assumptions, and explicitly state how you handle users with no prior activity (e.g., new users cannot be retained or churned). Also, consider using a calendar table or date spine to ensure all platforms are represented even if no activity occurred.
Confirm the table structure, date column, user ID, platform, and event timestamp. Verify definitions of new, retained, churned, and net users, and the target date.
Create CTEs to get distinct users active on the target date and on the day before, grouped by platform. Use date functions to filter events.
Use a CTE to find users whose first-ever event (minimum event date) is the target date, grouped by platform.
Join the active users from the target date and day before: retained are those active on both days; churned are those active on the day before but not on the target date.
Join the new, retained, and churned CTEs by platform, then calculate net as new + retained - churned. Handle missing platforms with COALESCE or a platform dimension table.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.