Longest online streak per driver

mediumSQL~25 min · 4 tests · ridelog

driver_days has one row per day a driver was online. A run of consecutive online days is a streak. Days off end a streak.

Ops wants each driver’s longest streak and the day it started.

Return one row per driver in driver_days with:

column type meaning
driver_id integer the driver
longest_streak_days integer number of days in the driver’s longest streak
streak_start date first day of that streak

Edge cases:

  • If a driver has two streaks of the same longest length, report the one that started first.
  • A driver with a single online day has a longest streak of 1.
  • The same day can appear twice for a driver. Count it once.

Row order doesn’t matter.

Tables: driver_days.

Learn the ideaRead the lesson →
solution.sqlDuckDB · ridelog

Press ⌘ ↵ or Run to check the visible tests. Submit runs the hidden ones too. Everything runs in your browser.

⌘ ↵ to run