SQL 50, decoded
0 of 50 solved/50

1141. User Activity for the Past 30 Days I

SQL 50 · Sorting and Grouping (day 4). Decode it with the hints, solve it on LeetCode, then compare with the reference solution in MySQLPostgreSQL.

EasySolve it on LeetCode ↗

Your work

Hints

Open one at a time. Try to finish with as few as you can.

1. What does one output row represent?
One day.
2. Approach
WHERE activity_date in the 30 days ending 2019-07-27, GROUP BY activity_date, COUNT(DISTINCT user_id).
3. The trap
The window is 2019-06-28 to 2019-07-27, both ends included.

Reference solution

Tested on MySQL 8.0 and PostgreSQL 16. Switch dialect at the top of the page.

Show the MySQLPostgreSQL solution
SELECT activity_date AS day, COUNT(DISTINCT user_id) AS active_users
FROM Activity
WHERE activity_date BETWEEN '2019-06-28' AND '2019-07-27'
GROUP BY activity_date;