Digits
n Data
Netflix SQL Interview Question 04

Churn
Risk
Users

Find users who have not watched any content in the last 30 days.

Schema

Table
Setup

Column NameTypeDescription
user_idintegerUser identifier.
subscription_typevarcharSubscription plan.
last_active_datedateMost recent watch date.

Sample Data

Input
Output

Sample Input: users
user_idsubscription_typelast_active_date
101Premium2024-01-01
102Basic2024-02-20
103Standard2024-01-10
104Premium2024-02-15
105Basic2024-01-20
106Standard2024-02-25
107Premium2024-01-05
Expected Output
user_id
101
103
105
107

SQL Editor

Run
Query

postgresql
Waiting for query

user_id
101
103
105
107

Hints

Unlock
Clues

Hint 01: The table already has each user's last activity.
Hint 02: Inactive means last_active_date is older than 30 days.
Hint 03: Select only user_id.

Solution

Locked
Answer

Solution is locked until you decide to reveal it. Try the editor first, then open this when you want the reference answer.

SELECT
  user_id
FROM users
WHERE last_active_date < CURRENT_DATE - INTERVAL '30 days';

Explanation

Step By
Step

01

Read each user's last_active_date.

02

Compare it with the current date minus 30 days.

03

Return users whose last activity is before that cutoff.

Related Questions

Keep
Solving