Skip to main content

Consecutive Logins

MediumPremium

You want to understand how often users log in to your company’s website. You're given a table named user_activity_log with the following columns:

  • user_id (INT) - Unique identifier for each user.
  • timestamp (DATETIME) - The exact time the user performed an activity.
  • activity_type (VARCHAR) - The type of activity the user has performed. The only two types of activities are LOGIN and LOGOUT.

Write a SQL query that determines the time elapsed (in minutes) between consecutive logins for each user. The result should show each user and the gap between their logins. Your output should contain the following columns: user_id, current_login, previous_login, minutes_elapsed. Round to the nearest minute