This should give what you're looking for
SELECT PKID,ID,[Date],RoleId,Status
FROM
(
SELECT *,LAG(Status,1,NULL) OVER (PARTITION BY ID ORDER BY [Date]) AS PrevStatus,
COUNT(1) OVER (PARTITION BY ID) AS Cnt
FROM Table
)t
WHERE (PrevStatus = 'Close' OR Cnt = 1)
AND STatus = 'Approved'
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://ift.tt/19nLNVq http://ift.tt/1iEAj0c
No comments:
Post a Comment