sql >> Base de Datos >  >> RDS >> Sqlserver

MSSQL 2008:obtenga el último registro actualizado por campo específico

En SQL Server 2012, solo usaría lag() . Puede replicar esto de varias maneras en SQL Server 2008. Aquí hay un método que usa 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;