merge back to back rows based on start & end date I have a table as below, each row has status, from and to ordered by Zone. Where To  of a current row always matches From of next row in that zone.

Zone  Status   From        To  
z1    Open     2015-01-01  2015-01-05 
z1    Open     2015-01-05  2015-01-10
z1    Closed   2015-01-10  2015-01-15 
z1    Closed   2015-01-15  2015-01-20
z1    Open     2015-01-20  2015-01-25
z1    Open     2015-01-25  2015-01-26

z2    Closed   2015-01-01  2015-01-05
z2    Closed   2015-01-05  2015-01-10
z2    Closed   2015-01-10  2015-01-15
z2    Closed   2015-01-15  2015-01-18
z2    Open     2015-01-18  2015-01-19
z2    Open     2015-01-19  2015-01-20
z2    Closed   2015-01-20  2015-01-20


I want to convert above into below table

Zone  Status   From        To  
z1    Open     2015-01-01  2015-01-10
z1    Closed   2015-01-10  2015-01-20
z1    Open     2015-01-20  2015-01-26

z2    Closed   2015-01-01  2015-01-18
z2    Open     2015-01-18  2015-01-20
z2    Closed   2015-01-20  2015-01-20


Any suggestions? 
Thanks
WITH x AS
(
SELECT
    Zone,
    Status,
    CASE WHEN 
             COALESCE(LAG(Status) 
             OVER (PARTITION BY Zone ORDER BY Zone, [From]), '') &lt;&gt; Status
         THEN 1 ELSE 0 END AS LS,
    [From],
    [To]
FROM
    t
), Y AS
(
SELECT
    Zone,
    Status,
    SUM(LS) OVER (PARTITION BY Zone ORDER BY Zone, [From]) Grp,
    [From],
    [To]
FROM
    x
)
SELECT
    Zone,
    Status,
    MIN([From]) [From],
    MAX([To]) [To]
FROM
    y
GROUP BY
   Zone, Status, Grp
ORDER BY 
   Grp;




Zone | Status | From                | To                 
:--- | :----- | :------------------ | :------------------
z1   | Open   | 01/01/2015 00:00:00 | 10/01/2015 00:00:00
z1   | Closed | 10/01/2015 00:00:00 | 20/01/2015 00:00:00
z1   | Open   | 20/01/2015 00:00:00 | 26/01/2015 00:00:00



db&lt;>fiddle here