Back to questions

Reactivated Users Facebook SQL Interview Question

Reactivated Users

Facebook SQL Interview Question

This is the same question as problem #31 in the SQL Chapter of Ace the Data Science Interview!

Imagine you're provided with a table containing information about user logins on Facebook in 2022. Write a query that determines the number of reactivated users for a given month. Reactivated users are those who were inactive the previous month but logged in during the current month.

Output the month in numerical format along with the count of reactivated users.

Here's some important assumptions to consider:

  • The table only contains data for the year 2022 and there are no missing dates within that period.
  • For instance, if a user whose first login date is on 3 March 2022, we assume that they had previously logged in during the year 2021. Although the data for their previous logins is not present in the table, we consider these users as reactivated users.

As of Aug 4th, 2023, we have carefully reviewed the feedback received and made necessary updates to the solution.

Table:

Column NameType
user_idinteger
login_datedatetime

Table:

user_idlogin_date
12302/22/2022 12:00:00
11203/15/2022 12:00:00
24503/28/2022 12:00:00
12305/01/2022 12:00:00
72505/25/2022 12:00:00

Example Output:

mthreactivated_users
21
32
52

In February 2022, we have 1 reactivated user, user 123. They had previously logged in during 2021 and recently reactivated their account in February 2022.

In March 2022, we have 2 reactivated users. Users 112 and 245 were inactive in the previous months but logged in during March 2022, indicating that they reactivated their accounts.

Moving on to May 2022, we still have 2 reactivated users. User 123, who had previously reactivated in February 2022, reactivated their account again in May 2022. Additionally, user 725, who was inactive in the previous months, logged in during May 2022, indicating that they reactivated their account once again.

The dataset you are querying against may have different input & output - this is just an example!

Input

Output