# Consecutive Logins — SQL Interview Question

Aced (formerly Exponent) publishes a public search API over its indexed pages; the guide is at https://www.aced.io/agents/agent-access.

Source: https://www.aced.io/questions/3100/consecutive-logins
Source observed: 2026-11-04T23:34:31.396Z
Last checked: 2026-11-04T23:34:31.396+00:00
Indexed: 2026-11-06T15:56:30.822+00:00

---

# Consecutive Logins

**Difficulty:** Medium  
**Categories:** [Coding](https://www.aced.io/questions?type=coding), [SQL](https://www.aced.io/questions?type=sql)  
**Interview status:** Coding; reported last asked 3 years ago

We provide this SQL practice question for analyzing user login activity. The task concerns a company website's `user_activity_log` table and asks you to calculate the elapsed time between each user's consecutive logins.

## Problem

You are given a table named `user_activity_log` with these columns:

| Column | Type | Description |
|---|---|---|
| `user_id` | `INT` | Unique identifier for each user. |
| `timestamp` | `DATETIME` | The exact time the user performed an activity. |
| `activity_type` | `VARCHAR` | The activity type. The only possible values 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 must contain:

- `user_id`
- `current_login`
- `previous_login`
- `minutes_elapsed`

Round `minutes_elapsed` to the nearest minute.

## Practice and access

The question includes separate **Question**, **Solution**, and **Community** views. No answers have been contributed by the community yet. Detailed company statistics for this question are available through [Upgrade](https://www.aced.io/upgrade?src=questions). You can [sign up to run code](https://www.aced.io/signup?src=lesson).

## Related question

- [Maximum Coins From K Consecutive Bags](https://www.aced.io/questions/7316/find-maximum-coins-k-consecutive-bags)

## About Aced

We are Aced, formerly Exponent. We offer interview preparation through courses and practice for Product Management, Forward Deployed Engineering, Engineering Management, Software Engineering, System Design, Data Science, Machine Learning, Data Engineering, and other technical and business roles.

---

[Read this page’s summary](https://www.aced.io/agents/api/public/v1/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F3100%2Fconsecutive-logins&trace=t_679ff9ab98f3)

## Ask a follow-up about this page

Need a more specific answer? Ask the exact question you have. It returns a fresh, cited answer from Aced (formerly Exponent)’s knowledge base. No account or API key required.

Open this URL with your own question, URL-encoded. Include your question in q. All research inputs are optional; no account or setup.

`GET https://www.aced.io/agents/agent/faq?q={question}&trace=t_679ff9ab98f3`

[Tool guide and examples](https://www.aced.io/agents/agent-access) · [OpenAPI](https://www.aced.io/agents/api/public/v1/openapi.json) · [Page TLDR form](https://www.aced.io/agents/agent-tools/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F3100%2Fconsecutive-logins). Opening a form does not execute a tool.