SQL interview question: Longest Winning Streak

Longest Winning Streak in Games

Sports analytics needs to find each player's longest consecutive winning streak.

Calculate the maximum number of consecutive wins for each player (gaps and islands problem).

Return player_id and longest_win_streak. Use ROW_NUMBER() minus game_id to identify consecutive groups.

Skills: advanced gaps and islands pattern with streak tracking

Tables

game_results 15 rows
  • game_id integer PK
  • player_id integer
  • game_date text
  • result text
game_idplayer_idgame_dateresult
112025-01-01win
212025-01-02win
312025-01-03win

Keep going