Skip to content
Advertisement

compute time difference between rows and conditional group by using PostgreSQL

I have data like as shown below:

If the time difference between rows is <= 5 mins, assign them the same id as shown below. I expect my output to be like as shown below:

I was trying something like below

Advertisement

Answer

You just need a cumulative sum:

Here is a db<>fiddle.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement