Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

SQL:come selezionare un singolo record per più ID sulla base del massimo datetime?

SELECT        a.Id, a.WindSpeed, a.DateTime
FROM          YourTable AS a
INNER JOIN     
(
    SELECT    ID, Max(DateTime) AS DateTime
    FROM      YourTable
    GROUP BY  ID
) AS b
ON            a.ID = b.ID
AND           a.DateTime = b.DateTime