Sqlserver
 sql >> Datenbank >  >> RDS >> Sqlserver

Abrufen des letzten Datensatzes in jeder Gruppe aus der Datenbank – SQL Server 2005/2008

;with cteRowNumber as (
    select COMPUTERNAME, SERIALNUMBER, USERNAME, LASTIP, LASTUPDATE, SOURCE,
           row_number() over(partition by COMPUTERNAME order by LASTUPDATE desc) as RowNum
        from YourTable
)
select COMPUTERNAME, SERIALNUMBER, USERNAME, LASTIP, LASTUPDATE, SOURCE
    from cteRowNumber
    where RowNum = 1