Churn Prediction

ASKED IN INTERVIEW
10pts
Meta

Problem Statement

Meta’s growth team defines a "Churn Risk" user as someone whose total platform activity (posts, likes, comments) has dropped by 50% or more compared to the previous month.

Write a query to identify these users. A user should be flagged for every month where their activity was 50% or less of what it was in the immediately preceding month.

Rules:

  • Consider activity across all types (post, like, comment).
  • A user must have at least 1 action in the previous month to be evaluated for churn.
  • The drop is calculated as: Current_Month_Activity / Previous_Month_Activity.
  • If the result is 0.5 or less, the user is at risk.
  • Output columns: user_id, report_month, activity_drop_ratio.
  • Round activity_drop_ratio to 2 decimal places.
  • Sort the result by user_id in ascending order, then report_month in ascending order.

Table Schema:

  • User_Actions: action_id, user_id, action_type, action_date.
  • Users: user_id, user_name, join_date.
  • Action_Types: type_id, action_type, engagement_weight.
Tests your understanding of
Window Functions, LAG, Percentage Change and Filtering

Input Tables

User_Actions
action_id(INTEGER)user_id(INTEGER)action_type(VARCHAR)action_date(DATE)
11post2026-01-10
21like2026-01-15
31comment2026-01-20
41post2026-01-25
51like2026-02-05
61like2026-02-10
12post2026-01-01
12post2026-02-01
Users
user_id(INTEGER)user_name(VARCHAR)
1Alice
2Bob
Action_Types
type_id(INTEGER)action_type(VARCHAR)
1post
2like
3comment

Expected Output

user_id(INTEGER)report_month(VARCHAR)activity_drop_ratio(DECIMAL)
12026-020.5

Tags

HardASKED IN INTERVIEWWindow FunctionsLAGPercentage ChangeFiltering
25-30 min
29%

Hints