SQLhardGaps islands~22m
A video streaming platform tracks user viewing sessions
Problem
A video streaming platform tracks user viewing sessions. Find all gaps in viewing activity for each user where they were inactive for 3 or more consecutive days, and return the gap start date, gap end date, and gap duration in days. Only include users who have had at least one such gap, and order by user_id, then by gap_start_date.
Examples
Example 1
Example 2
Constraints
- ›Return user_id, gap_start_date, gap_end_date, gap_duration_days
- ›Only gaps of 3+ consecutive days
- ›Only users with at least one qualifying gap
- ›Order by user_id, then gap_start_date
Reference solution
Reference solution available after you attempt the question.
Ready to solve it?
Start a session on Mockbit #42. Write your SQL, run it against real data, and get graded on correctness, efficiency, query structure, and business understanding.
Related SQL questions
- #62FitFlex gym chain tracks member gym attendance through entry card swipeshard
- #63A streaming platform wants to identify episodes that are experiencing...hard
- #64A major investment bank needs to identify potentially fraudulent card...hard
- #41You're analyzing user engagement for a social media platformeasy
- #43A regional bank wants to analyze account activity by branch locationeasy
← Back homemockbit.io/q/42