Generates a weekly cohort retention query with a full date spine so zero-activity users appear as 0% retention rather than being dropped as NULL.
Generates a weekly cohort retention query with a full date spine so zero-activity users appear as 0% retention rather than being dropped as NULL. Use this when building retention dashboards that need accurate week-over-week cohort metrics.
Act as a Product Analytics Engineer. Build cohort retention in [database].
Tables: users(user_id, signup_date, plan_type),
events(user_id, event_type, event_date).
Goal: weekly retention by signup cohort, last 12 weeks.
Retained = at least one [event_type] in week N post-signup.
Return: cohort_week, weeks_since_signup, cohort_size, retained_users,
retention_rate (decimal). Handle zero-event users as 0%, not NULL.
Comment the date spine logic.
Source: https://www.buildfastwithai.com/blogs/ai-prompts-data-analyst-python-sql-chatgpt-2026