Skip to content
Advertisement

I want to group time interval based on given tolerance in postgres sql

——output will be like—-

So the above output should be regrouped in such a manner that for same id and name , timeint with 1 sec tolerance should be considered as same

______ expected output _________________

Advertisement

Answer

The general solution to your problem requires a recursive CTE. If all times are accurate to one second and you only want two seconds, there might be a way around that.

However, this solution uses a recursive CTE:

Here is a db<>fiddle.

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