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
Hi Kanch,
so you don't want all the changes, just the last one plus the most current row:
Dieter