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!
Assuming the ID column as Primary_key I have made the following sample query:
Please let me know if anything is ambigous!