Is there a way to assign unique Group ID to rows in SQL based off on how much time is between each one (in this case 60 minutes). For patient 614 I would like to start the first row at 12:50pm and that would be Group ID 1 and since the next BP is past 1:50pm (60 minutes), it would be Group ID 1 since its at 4:05pm. But the next Blood Pressure is at 5:00pm (within 60 minutes of 4:05pm, so it would be Group ID 2.
For patient 297 I would need to it to start at the first row (8/27 at 1pm since this is the first Blood Pressure) and this would be row # 1 and then start going through each row (to see if a row is <= 60 min from 1pm), if it is it would be #2, then #3, etc. But once its over 60 min, I then need it to start over again at the next #1 grouping (which is anything over 60 minutes or the next patient CSN), and use the same logic, going through each row to see if <= 60 min. I've included a screen shot of the expected Group ID I would like to see for each patient.
The grouping would also need to start over at a new patient, since patients have unique ID (CSN).
Desired Outcome: