Reactivated Users Per Month
Spotify 🧠 Hard SQL
Beginner Mode

Objective

You are given a table of user login records. Each row represents a single login event with the user ID and the date they logged in.

Table Schema:

The user_logins table:

Column Type Description
user_id integer ID of the user
login_date date Date of the login

Task Requirements:

  • A reactivated user is one who logged in during the current month, did not log in during the previous month, but had logged in during some earlier month
  • For each month, count the number of reactivated users
  • Do not count brand new users who have no login history before the current month
  • Months with zero reactivated users should not appear in the output
  • Order the results by month in ascending order



Output columns: month, reactivated_users

Examples

Example 1:

Input:

user_logins
login_dateuser_id
2025-01-051
2025-01-151
2025-02-101
2025-04-081
2025-01-032
2025-03-122
2025-04-202
2025-01-103
2025-02-143
2025-03-053
2025-02-204
2025-04-154
2025-03-185
2025-04-255
2025-04-106

Output:
monthreactivated_users
2025-03-011
2025-04-012
Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →