My first instinct was to just group by post_date and call it a day, which would've completely missed the cohort part.
First, compute each user's earliest post date using a window function or subquery to assign them to a cohort. Then, aggregate posts by cohort and posting date, counting total posts and distinct active users, and order the results by cohort start date and posting date.
Pro tip: Clarify whether 'active user' means a user who posted on that date or any user in the cohort who was active (e.g., logged in) that day; in most cases, it refers to distinct users who posted on that date. Also, consider using a CTE for readability and to avoid repeating the cohort calculation.
Use a window function like MIN(post_date) OVER (PARTITION BY user_id) or a subquery to find each user's earliest post date, which defines their cohort.
Join the cohort assignment back to the original posts table so each post row has the user's cohort start date.
Group by cohort start date and post date, then compute COUNT(*) for total posts and COUNT(DISTINCT user_id) for active users.
Sort the final output by cohort start date and then by posting date to meet the requirement.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.