bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 1141. User Activity for the Past 30 Days I

1141. User Activity for the Past 30 Days I

Leetcode Solutions

Key approach of the solution

  1. Select the activity_date and user_id columns from the Activity table.
  2. Apply a WHERE clause to filter records that fall within the 30-day period ending on '2019-07-27'.
  3. Use the DATEDIFF function to calculate the difference in days between '2019-07-27' and the activity_date.
  4. Ensure the difference is between 0 and 29 days (inclusive) to cover the 30-day period.
  5. Group the results by activity_date.
  6. Use the COUNT(DISTINCT user_id) function to count the number of unique active users for each day.
  7. Alias the activity_date as day and the count as active_users in the SELECT statement.
erDiagram
    Activity {
        int user_id
        int session_id
        date activity_date
        enum activity_type
    }

Alternative approach of the solution

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...