AnalystPath

Sessions Running Concurrently

SQLHardSenior levelPinterest~15 min

Problem

**[Asked at Pinterest]**

Pinterest monitors server load by tracking overlapping user sessions.
Two sessions overlap if one starts before the other ends.

For each session, count how many **other** sessions were running at the
same time (i.e., their time intervals overlap with this session's interval).

Return `session_id` and `concurrent_count`, ordered by session_id.

Tables

Example rows — the live problem includes the full dataset.

sessions
session_iduser_idsession_startsession_end

Expected output

Your answer should return 5 rows with the columns session_id, concurrent_count.

Starter code (SQL)

SELECT *
FROM sessions;

Solve this SQL question free

Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related SQL questions