SQL
Lab
Microsoft Microsoft Enterprise Apps Interview Question 08

Daily
Active
Users

Find daily active users across all products.

Table Schema

Inspect
Table

interactive
ColumnType
user_idinteger
activity_datedate
product_namevarchar

Sample Data

Input
Output

Sample Input: activity_logs
user_idactivity_dateproduct_name
1012024-01-01Teams
1022024-01-01Outlook
1012024-01-02Azure
1032024-01-02Teams
1042024-01-03Outlook
Expected Output
activity_dateactive_users
2024-01-012
2024-01-022
2024-01-031

SQL Editor

Run
Query

postgresql
Waiting for query

activity_dateactive_users
2024-01-012
2024-01-022
2024-01-031

Hints

Unlock
Clues

Hint 01: Identify the grouping level required by the output.
Hint 02: Aggregate with COUNT, SUM, AVG, or a window function as needed.
Hint 03: Filter after aggregation with HAVING or after ranking with an outer query.

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

Explanation

Step By
Step

01

Read the expected output columns to determine the final grain.

02

Aggregate or rank the input rows to calculate the requested metric.

03

Filter, sort, and alias the final columns to match the output.

Related Questions

Keep
Solving