AnalystPath

Monthly Retained Users

SQLHardSenior levelMeta~15 min

Problem

**[Asked at Facebook/Meta]**

A user is considered **retained** in a given month if they were active in
BOTH that month AND the previous month.

Given a table of user activity logs, count the number of retained users for
each month in 2023. Order by month.

Tables

Example rows — the live problem includes the full dataset.

activity_log
log_iduser_idevent_typeevent_date

Expected output

Your answer should return 3 rows with the columns activity_month, retained_users.

Starter code (SQL)

SELECT *
FROM activity_log;

Solve this SQL question free

Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related SQL questions