Table Schema
Inspect
Table
| Column | Type |
|---|---|
| user_id | integer |
| stream_date | date |
Find number of active listeners per day.
Table Schema
| Column | Type |
|---|---|
| user_id | integer |
| stream_date | date |
Sample Data
| user_id | stream_date |
|---|---|
| 101 | 2024-01-01 |
| 102 | 2024-01-01 |
| 101 | 2024-01-02 |
| 103 | 2024-01-02 |
| 104 | 2024-01-03 |
| 105 | 2024-01-03 |
| 106 | 2024-01-03 |
| stream_date | active_users |
|---|---|
| 2024-01-01 | 2 |
| 2024-01-02 | 2 |
| 2024-01-03 | 3 |
SQL Editor
| stream_date | active_users |
|---|---|
| 2024-01-01 | 2 |
| 2024-01-02 | 2 |
| 2024-01-03 | 3 |
Hints
Solution
Solution is locked until you decide to reveal it. Try the editor first, then open this when you want the reference answer.
SELECT stream_date, COUNT(DISTINCT user_id) AS active_users FROM streams GROUP BY stream_date;
Explanation
Read the expected output columns to determine the final grain.
Aggregate or rank the input rows to calculate the requested metric.
Filter, sort, and alias the final columns to match the output.
Related Questions