In SQL Server 2012, dovresti semplicemente usare lag()
. Puoi replicarlo in vari modi in SQL Server 2008. Ecco un metodo che utilizza cross apply
:
select c.*
from content c cross apply
(select top 1 c2.*
from content c2
where c2.contentId = c.contentId and c2.UpdatedAt < c.UpdatedAt
order by c2.UpdatedAt desc
) cprev
where c.FileId <> cprev.FileId;