Merging intervals in one pass in SQL

前端 未结 4 748
轻奢々
轻奢々 2020-12-06 13:02

Let\'s say I have a table with two columns: start and end, both integers, and the table is ordered by the first, then second column. Each row repr

4条回答
  •  再見小時候
    2020-12-06 13:40

    In your links you have omitted one: Can I use a SQL Server CTE to merge intersecting dates? where I present a RECURSIVE CTE solution to the overlapping intervals problem. Recursive CTE's can be handled differently (compared to ordinary self-joins), and often perform amazingly fast.

    mysql does not have recursive CTEs. Postgres has them, Oracle has them, Microsoft has them.

    Here Querying for a 'run' of consecutive columns in Postgres is another one, with a fudge-factor.

    Here Get total time interval from multiple rows if sequence not broken is yet another one.

提交回复
热议问题