Calculate DAU, WAU, MAU for an E-commerce Platform

SQL coding challenge · Difficulty: hard · Topic: DAU / WAU / MAU Metrics · +200 XP

An e-commerce platform wants to track user engagement. Given a user_activity table of login records, compute three metrics for each date in the data:

Return activity_date, DAU, WAU, MAU, ordered by activity_date ascending.

Example input

user_activity table:

| activity_id | user_id | activity_date |
| --- | --- | --- |
| 1 | 201 | 2024-01-01 |
| 2 | 202 | 2024-01-01 |
| 3 | 203 | 2024-01-01 |
| 4 | 201 | 2024-01-02 |
| 5 | 202 | 2024-01-03 |
| 6 | 204 | 2024-01-03 |
| 7 | 205 | 2024-01-04 |

Expected output

| activity_date | DAU | WAU | MAU |
| --- | --- | --- | --- |
| 2024-01-01 | 3 | 3 | 3 |
| 2024-01-02 | 1 | 3 | 3 |
| 2024-01-03 | 2 | 4 | 4 |
| 2024-01-04 | 1 | 5 | 5 |

What this SQL challenge teaches you

“Calculate DAU, WAU, MAU for an E-commerce Platform” is a hard-level SQL challenge focused on DAU / WAU / MAU Metrics. Working through it gives you hands-on practice with window functions, aggregation, date — the kind of transformation you are asked to write in real data engineering work and in technical interviews. You can solve it directly in the browser: the dataset is pre-loaded, so you write the query or DataFrame code, run it, and compare your output against the expected result immediately.

Concepts covered

How to approach it

If you get stuck, work through these steps in order before looking at a full solution — each one narrows the problem down:

  1. 1 ≤ number of rows ≤ 100,000
  2. Each user_id appears between 1 and 500 times
  3. activity_date values are valid dates in YYYY-MM-DD format
  4. Return columns: activity_date (DATE), DAU (INTEGER), WAU (INTEGER), MAU (INTEGER), ordered by activity_date ASC
  5. DAU, WAU, MAU must be calculated for each distinct activity_date

How to practise it on PySpark.in

Open the challenge, write your SQL query in the editor and press Run to execute it against the sample dataset. Submitting checks your output against every test case, including hidden ones, so you find out straight away whether your logic holds up. You can retry as often as you like, and each solved challenge adds to your XP.

Related SQL challenges

Frequently asked questions

Do I need to install Spark or a database to solve this?

No. The SQL environment runs in your browser with the sample data already loaded, so there is nothing to install or configure.

Is this challenge free?

Yes - the problem, the sample dataset, the hints and unlimited test runs are free.

What level is it?

It is rated hard and covers DAU / WAU / MAU Metrics.

Solve this challenge free on PySpark.in