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

qualify rank() over (partition.....question - response (10) by dnoeth

$
0
0

Hi Kanch,
so you don't want all the changes, just the last one plus the most current row:

SELECT *    
FROM 
 (
   SELECT * FROM tab
   QUALIFY -- get the most current row and all rows where the status changes in the next row
      COALESCE(
         MIN(status) 
         OVER (PARTITION BY companyid 
               ORDER BY effectivedate 
               ROWS BETWEEN 1 FOLLOWING AND 1 FOLLOWING)
         ,status||'x') <> status
 ) dt
QUALIFY -- get the current and the previous row
   RANK() 
   OVER (PARTITION BY companyid 
         ORDER BY effectivedate DESC) <= 2

Dieter


Viewing all articles
Browse latest Browse all 27759

Trending Articles



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