Save 25%Black Friday: 25% off all plans — use code BLACKFRIDAY2026 at checkout. Ends Friday, Dec 4.Claim the deal

Table: user_actions

+-------------+--------------+
| Column Name | Type         |
+-------------+--------------+
| user_id     | int          |
| event_id    | int          |
| event_type  | varchar(255) |
| event_date  | date         |
+-------------+--------------+

(user_id, event_id) is the primary key. Each row records one user action.

For users active in January 2023, compute the weekly churn rate for each ISO week. The week is the Monday-starting ISO week containing event_date. Churn rate for week W is users active in W but not active in the following week, divided by users active in W. Only include weeks from January 2023. Round to 2 decimal places. Return week and churn_rate, ordered by week ascending.

The result format is shown below.

Example

Input:

user_actions table:
+---------+----------+------------+------------+
| user_id | event_id | event_type | event_date |
+---------+----------+------------+------------+
| 1       | 1        | login      | 2023-01-02 |
| 1       | 2        | login      | 2023-01-09 |
| 2       | 3        | login      | 2023-01-02 |
| 3       | 4        | login      | 2023-01-02 |
| 3       | 5        | login      | 2023-01-09 |
| 4       | 6        | login      | 2023-01-09 |
| 4       | 7        | login      | 2023-01-16 |
+---------+----------+------------+------------+

Output:

+------------+------------+
| week       | churn_rate |
+------------+------------+
| 2023-01-02 | 0.33       |
| 2023-01-09 | 0.67       |
+------------+------------+

Explanation:
For the week of 2023-01-02, users 1, 2, and 3 are active, and only users 1 and 3 return the next week. The churn rate is 1 / 3 = 0.33. For the week of 2023-01-09, users 1, 3, and 4 are active, and only user 4 returns the next week. The churn rate is 2 / 3 = 0.67.


Accepted
18/69
Acceptance Rate26.1%
Test Cases
Input
-
Output
-
Expected
-