Write a SQL query to find the rolling 7-day average of active users, partitioned by specific clinical cohorts at nference.
Use the provided cohort, user, and activity data. Include calendar dates with no activity so inactive days contribute zero to the average.
Output
- One row per clinical cohort and calendar date in the activity range
- Columns:
cohort_id, cohort_name, activity_date, daily_active_users, and rolling_7_day_avg
- Include all cohorts represented by users, order by
cohort_id, then activity_date
Output details
- Order both
cohort_id and activity_date in ascending order.
- Use an inclusive date range from the minimum through maximum non-NULL
activity_date.
- Count each user only once per cohort and
activity_date.
- Treat missing daily counts as zero.
- Use the current day plus six preceding calendar days, using a shorter window at the range start.
- Round
rolling_7_day_avg to two decimal places.