Quantcast
Channel: Teradata Forums - All forums
Viewing all articles
Browse latest Browse all 27759

Need to calculate using LEAD, LAG function - response (9) by dnoeth

$
0
0
Your expected output is probably wrong, the 3rd leave start on 7/1/2010 according to your date not on 7/1/2011. This combines the rows from the first "leave" up to the next "active" row: SELECT emplid, MIN(effdt) AS LEAVE_START_DATE, x AS LEAVE_END_DATE FROM ( SELECT t.*, MIN(CASE WHEN empl_status = 'active' THEN effdt END) OVER (PARTITION BY emplid ORDER BY effdt, sequence ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) AS x FROM dropme AS t QUALIFY empl_status = 'LEAVE' ) AS dt GROUP BY 1,xDieter

Viewing all articles
Browse latest Browse all 27759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>