AlgoMaster Logo

Exercise: Consecutive Records and Streaks

Last Updated: May 12, 2026

1 min read

For this exercise, we will work with below data:

SQL

Exercise 1

Easy

Write a query that returns each user's distinct streaming dates from the streams table. Show user_id and stream_date, ordered by user_id and stream_date.

SQL

Expected Query

Expected Output

Exercise 2

Medium

Write a query that returns all listening streaks for every user, grouping consecutive days into islands using the ROW_NUMBER difference technique. Show user_idstreak_startstreak_end, and streak_days. Order by user_idstreak_start.

SQL

Expected Query

Expected Output

Exercise 3

Hard

Write a query that returns the longest single streak across all users. Show usernamestreak_startstreak_end, and streak_days. If multiple users tie for the longest streak, include all of them. Order by usernamestreak_start.

SQL

Expected Query

Expected Output