blog.apolloner.eu

Interval coalescence in SQL

Recently I needed to coalescence intervals in SQL. There are already existing solutions to this problem, but for my taste neither of them was really nice or easy to understand (At least none of them had good explanations). So here is my solution for this problem -- and hopefully explained well enough.

Assume you have a database table like this (x is the start time and y the end time):

t x y
a 10:00 11:00
a 11:00 12:00
a 14:00 16:00
b 12:00 ...
Read More