Digits
n Data
Netflix SQL Interview Question 08

Daily
Active
Users

Find the number of active users per day.

Schema

Table
Setup

Column NameTypeDescription
user_idintegerUser identifier.
watch_datedateDate watched.

Sample Data

Input
Output

Sample Input: watching_activity
user_idwatch_date
1012024-01-01
1022024-01-01
1012024-01-02
1032024-01-02
1042024-01-03
1052024-01-03
1062024-01-03
Expected Output
watch_dateactive_users
2024-01-012
2024-01-022
2024-01-033

SQL Editor

Run
Query

postgresql
Waiting for query

watch_dateactive_users
2024-01-012
2024-01-022
2024-01-033

Hints

Unlock
Clues

Hint 01: Active means the user has a watch row that day.
Hint 02: COUNT(DISTINCT user_id) for each watch_date.
Hint 03: Order by date for readable output.

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
  watch_date,
  COUNT(DISTINCT user_id) AS active_users
FROM watching_activity
GROUP BY watch_date
ORDER BY watch_date;

Explanation

Step By
Step

01

Group rows by watch_date.

02

Count unique users in each date group.

03

Return one row per day.

Related Questions

Keep
Solving