Finding the largest group of consecutive numbers within a partition
I have the following data ordered by player_id and match_date. I would like to find out the group of records that has the maximum number of consecutive runs (4 runs from 2014-04-03 till 2014-04-12 for 3 consecutive times) player_id match_date runs 1 2014-04-01 5 1 2014-04-02 55 1 2014-04-03 4 1 2014-04-10 4 1 2014-04-12 4 1 2014-04-14 3 1 2014-04-19 4 1 2014-04-20 44 2 2014-04-01 23 2 2014-04-02 23 2 2014-04-03 23 2 2014-04-10 23 2 2014-04-12 4 2 2014-04-14 3 2 2014-04-19 23 2 2014-04-20 1 I have come up with the following SQL: select *,row_number() over (partition by ranked.player_id,ranked