Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

Need Analytical window query help - response (2) by msk.khurram

$
0
0

Assuming the ID column as Primary_key I have made the following sample query:

SELECT 
ID,
Status,
 CASE 
    WHEN  NEW_DATA.Status = OLD_DATA.STATUS 
            THEN 1 
    ELSE 0 
 END AS Status_Change_ind, 
 StartDate
FROM TABLENAME AS OLD_DATA 
LEFT JOIN
TABLENAME AS NEW_DATA
ON NEW_DATA.ID = OLD_DATA.ID
QUALIFY ROW_NUMBER() OVER(ORDER BY  StartDate) = 1;

Please let me know if anything is ambigous!
 


Viewing all articles
Browse latest Browse all 14773

Trending Articles



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