Loading...
Overlapping User Sessions
A medium SQL interview practice problem on DataDriven. Write and execute real sql code with instant grading.
- Domain
- SQL
- Difficulty
- medium
- Seniority
- mid
Problem
The user_sessions table records session windows with a start and end time. Some users have sessions that overlap in time. Find all pairs of overlapping sessions for the same user. Two sessions overlap if one starts before the other ends and vice versa. Return the user_id, the session_ids of both overlapping sessions, and their respective start times. Do not return a session paired with itself.
Practice This Problem
Solve this SQL problem with real code execution. DataDriven runs your SQL queries against a live PostgreSQL database and grades it instantly.