$ 0 0 SEL ID , STATUS , DT , MAX(STATUS) OVER(PARTITION BY ID ORDER BY DT ROWS 1 PRECEDING) AS COL1 , MIN(STATUS) OVER(PARTITION BY ID ORDER BY DT ROWS 1 PRECEDING) AS COL2 , CASE WHEN COL2 <> COL1 THEN 1 ELSE 0 END AS COL3 FROM MY_TABLE;
SEL ID , STATUS , DT , MAX(STATUS) OVER(PARTITION BY ID ORDER BY DT ROWS 1 PRECEDING) AS COL1 , MIN(STATUS) OVER(PARTITION BY ID ORDER BY DT ROWS 1 PRECEDING) AS COL2 , CASE WHEN COL2 <> COL1 THEN 1 ELSE 0 END AS COL3 FROM MY_TABLE;