merge DATE-rows if episodes are in direct succession or overlapping

后端 未结 4 886
我寻月下人不归
我寻月下人不归 2021-01-14 07:47

I have a table like this:

ID    BEGIN    END

If there are overlapping episodes for the same ID (like 2000-01-01 - 2001-1

4条回答
  •  独厮守ぢ
    2021-01-14 08:16

    Regarding your second concern, I'm not sure about PostgreSQL, but in SQL Server there's a DATEDIFF(interval, start_date, end_date) that gives you the interval specified between two dates. You could use the MIN(Begin) as a start date and MAX(End) as end date to get the interval difference. You could then use this in a case statement to output something, although you might be needing to make a sub-query or something equivalent for your scenario.

提交回复
热议问题